예제 #1
0
        protected bool IsEqual(object lhs, object rhs)
        {
            if (TypeConverter.IsNumeric(lhs) && TypeConverter.IsNumeric(rhs))
            {
                lhs = (decimal)TypeConverter.To(lhs, typeof(decimal));
                rhs = (decimal)TypeConverter.To(rhs, typeof(decimal));
            }
            if ((TypeConverter.IsEnum(lhs) && rhs is string) ||
                (lhs is string && TypeConverter.IsEnum(rhs)))
            {
                return(Equals(lhs?.ToString(), rhs?.ToString()));
            }

            return(Equals(lhs, rhs));
        }
예제 #2
0
        protected int Compare(IComparable lhs, IComparable rhs)
        {
            if (lhs == null || rhs == null)
            {
                return(lhs?.CompareTo(rhs) ?? (-1 * rhs?.CompareTo(lhs) ?? 0));
            }

            if (TypeConverter.IsNumeric(lhs) && TypeConverter.IsNumeric(rhs))
            {
                lhs = (decimal)TypeConverter.To(lhs, typeof(decimal));
                rhs = (decimal)TypeConverter.To(rhs, typeof(decimal));
            }
            if (!Equals(lhs.GetType(), rhs.GetType()))
            {
                throw ComparisionException.UnComparable(lhs.GetType(), rhs.GetType()).Decorate(Token);
            }
            return(lhs.CompareTo(rhs));
        }