Beispiel #1
0
        public int CompareUsingMostPreciseType(object a, object b)
        {
            //If any of the paremeter that is null, not is a string the method ChangeType fails
            if ((a == null || b == null) && (a != b) && options.AllowNullParameter())
            {
                return(-1);
            }
            Type mpt = options.AllowNullParameter()
                       // Allow nulls to be compared with other values
                ? GetMostPreciseType(a?.GetType(), b?.GetType()) ?? typeof(object)
                       // No breaking changes fallback
                : GetMostPreciseType(a.GetType(), b.GetType());

            return(Comparer.Default.Compare(Convert.ChangeType(a, mpt), Convert.ChangeType(b, mpt)));
        }
Beispiel #2
0
        public int CompareUsingMostPreciseType(object a, object b)
        {
            Type mpt = options.AllowNullParameter()
                       // Allow nulls to be compared with other values
                ? GetMostPreciseType(a?.GetType(), b?.GetType()) ?? typeof(object)
                       // No breaking changes fallback
                : GetMostPreciseType(a.GetType(), b.GetType());

            return(Comparer.Default.Compare(Convert.ChangeType(a, mpt), Convert.ChangeType(b, mpt)));
        }