

namespace MarcelJoachimKloubert.Extensions
{
    // IsLessOrEqual()
    static partial class MJKCoreExtensionMethods
    {
        #region Methods (1)

        /// <summary>
        /// Checks if a value is less or equal than another.
        /// </summary>
        /// <typeparam name="T">Type of the value.</typeparam>
        /// <param name="value">The value to check.</param>
        /// <param name="other">The value that should compared with <paramref name="value" />.</param>
        /// <returns>Is less than/equal or not.</returns>
        public static bool IsLessOrEqual<T>(this T value, T other)
            where T : global::System.IComparable<T>, global::System.IComparable
        {
            if (value != null)
            {
                return value.CompareTo(other) <= 0;
            }

            if (other != null)
            {
                return other.CompareTo(value) >= 0;
            }

            // both are (null), so they are equal
            return true;
        }

        #endregion Methods (1)
    }
}