예제 #1
0
파일: JValue.cs 프로젝트: conankzhang/fez
 private static int Compare(JTokenType valueType, object objA, object objB)
 {
   if (objA == null && objB == null)
     return 0;
   if (objA != null && objB == null)
     return 1;
   if (objA == null && objB != null)
     return -1;
   switch (valueType)
   {
     case JTokenType.Comment:
     case JTokenType.String:
     case JTokenType.Raw:
       return string.CompareOrdinal(Convert.ToString(objA, (IFormatProvider) CultureInfo.InvariantCulture), Convert.ToString(objB, (IFormatProvider) CultureInfo.InvariantCulture));
     case JTokenType.Integer:
       if (objA is ulong || objB is ulong || (objA is Decimal || objB is Decimal))
         return Convert.ToDecimal(objA, (IFormatProvider) CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, (IFormatProvider) CultureInfo.InvariantCulture));
       if (objA is float || objB is float || (objA is double || objB is double))
         return JValue.CompareFloat(objA, objB);
       else
         return Convert.ToInt64(objA, (IFormatProvider) CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, (IFormatProvider) CultureInfo.InvariantCulture));
     case JTokenType.Float:
       return JValue.CompareFloat(objA, objB);
     case JTokenType.Boolean:
       return Convert.ToBoolean(objA, (IFormatProvider) CultureInfo.InvariantCulture).CompareTo(Convert.ToBoolean(objB, (IFormatProvider) CultureInfo.InvariantCulture));
     case JTokenType.Date:
       return ((DateTime) objA).CompareTo(!(objB is DateTimeOffset) ? Convert.ToDateTime(objB, (IFormatProvider) CultureInfo.InvariantCulture) : ((DateTimeOffset) objB).DateTime);
     case JTokenType.Bytes:
       if (!(objB is byte[]))
         throw new ArgumentException("Object must be of type byte[].");
       byte[] a1 = objA as byte[];
       byte[] a2 = objB as byte[];
       if (a1 == null)
         return -1;
       if (a2 == null)
         return 1;
       else
         return MiscellaneousUtils.ByteArrayCompare(a1, a2);
     case JTokenType.Guid:
       if (!(objB is Guid))
         throw new ArgumentException("Object must be of type Guid.");
       else
         return ((Guid) objA).CompareTo((Guid) objB);
     case JTokenType.Uri:
       if (!(objB is Uri))
         throw new ArgumentException("Object must be of type Uri.");
       else
         return Comparer<string>.Default.Compare(((Uri) objA).ToString(), ((Uri) objB).ToString());
     case JTokenType.TimeSpan:
       if (!(objB is TimeSpan))
         throw new ArgumentException("Object must be of type TimeSpan.");
       else
         return ((TimeSpan) objA).CompareTo((TimeSpan) objB);
     default:
       throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", (object) valueType, StringUtils.FormatWith("Unexpected value type: {0}", (IFormatProvider) CultureInfo.InvariantCulture, (object) valueType));
   }
 }
예제 #2
0
파일: JValue.cs 프로젝트: angel2230/ZZZ
        private static bool Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(true);
            }
            if (objA == null || objB == null)
            {
                return(false);
            }

            switch (valueType)
            {
            case JTokenType.Integer:
                if (objA is ulong || objB is ulong)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                else
                {
                    return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).Equals(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));
                }

            case JTokenType.Float:
                double d1 = Convert.ToDouble(objA, CultureInfo.InvariantCulture);
                double d2 = Convert.ToDouble(objB, CultureInfo.InvariantCulture);
                if (d1.Equals(d2))
                {
                    return(true);
                }

                // take into account possible floating point errors
                return(MathUtils.ApproxEquals(d1, d2));

            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Boolean:
            case JTokenType.Raw:
                return(objA.Equals(objB));

            case JTokenType.Date:
                return(objA.Equals(objB));

            case JTokenType.Bytes:
                byte[] b1 = objA as byte[];
                byte[] b2 = objB as byte[];
                if (b1 == null || b2 == null)
                {
                    return(false);
                }

                return(MiscellaneousUtils.ByteArrayCompare(b1, b2));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }
예제 #3
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA == null && objB != null)
            {
                return(-1);
            }

            switch (valueType)
            {
            case JTokenType.Integer:
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
#endif
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                else if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(CompareFloat(objA, objB));
                }
                else
                {
                    return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));
                }

            case JTokenType.Float:
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
#endif
                return(CompareFloat(objA, objB));

            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
                string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);

                return(string.CompareOrdinal(s1, s2));

            case JTokenType.Boolean:
                bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);

                return(b1.CompareTo(b2));

            case JTokenType.Date:
#if !NET20
                if (objA is DateTime)
                {
#endif
                DateTime date1 = (DateTime)objA;
                DateTime date2;

#if !NET20
                if (objB is DateTimeOffset)
                {
                    date2 = ((DateTimeOffset)objB).DateTime;
                }
                else
#endif
                date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);

                return(date1.CompareTo(date2));

#if !NET20
            }
            else
            {
                DateTimeOffset date1 = (DateTimeOffset)objA;
                DateTimeOffset date2;

                if (objB is DateTimeOffset)
                {
                    date2 = (DateTimeOffset)objB;
                }
                else
                {
                    date2 = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
                }

                return(date1.CompareTo(date2));
            }
#endif
            case JTokenType.Bytes:
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }

                byte[] bytes1 = objA as byte[];
                byte[] bytes2 = objB as byte[];
                if (bytes1 == null)
                {
                    return(-1);
                }
                if (bytes2 == null)
                {
                    return(1);
                }

                return(MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2));

            case JTokenType.Guid:
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }

                Guid guid1 = (Guid)objA;
                Guid guid2 = (Guid)objB;

                return(guid1.CompareTo(guid2));

            case JTokenType.Uri:
                if (!(objB is Uri))
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }

                Uri uri1 = (Uri)objA;
                Uri uri2 = (Uri)objB;

                return(Comparer <string> .Default.Compare(uri1.ToString(), uri2.ToString()));

            case JTokenType.TimeSpan:
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }

                TimeSpan ts1 = (TimeSpan)objA;
                TimeSpan ts2 = (TimeSpan)objB;

                return(ts1.CompareTo(ts2));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }
예제 #4
0
        private static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA == null && objB != null)
            {
                return(-1);
            }

            switch (valueType)
            {
            case JTokenType.Integer:
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                else if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(CompareFloat(objA, objB));
                }
                else
                {
                    return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));
                }

            case JTokenType.Float:
                return(CompareFloat(objA, objB));

            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
                string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);

                return(s1.CompareTo(s2));

            case JTokenType.Boolean:
                bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);

                return(b1.CompareTo(b2));

            case JTokenType.Date:
                if (objA is DateTime)
                {
                    DateTime date1 = Convert.ToDateTime(objA, CultureInfo.InvariantCulture);
                    DateTime date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);

                    return(date1.CompareTo(date2));
                }
                else
                {
                    if (!(objB is DateTimeOffset))
                    {
                        throw new ArgumentException("Object must be of type DateTimeOffset.");
                    }

                    DateTimeOffset date1 = (DateTimeOffset)objA;
                    DateTimeOffset date2 = (DateTimeOffset)objB;

                    return(date1.CompareTo(date2));
                }

            case JTokenType.Bytes:
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }

                byte[] bytes1 = objA as byte[];
                byte[] bytes2 = objB as byte[];
                if (bytes1 == null)
                {
                    return(-1);
                }
                if (bytes2 == null)
                {
                    return(1);
                }

                return(MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }
예제 #5
0
        private static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA != null || objB == null)
            {
                switch (valueType)
                {
                case JTokenType.Integer:
                    if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                    {
                        return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                    }
                    if (objA is float || objB is float || objA is double || objB is double)
                    {
                        return(CompareFloat(objA, objB));
                    }
                    return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));

                case JTokenType.Float:
                    return(CompareFloat(objA, objB));

                case JTokenType.Comment:
                case JTokenType.String:
                case JTokenType.Raw:
                {
                    string text = Convert.ToString(objA, CultureInfo.InvariantCulture);
                    string strB = Convert.ToString(objB, CultureInfo.InvariantCulture);
                    return(text.CompareTo(strB));
                }

                case JTokenType.Boolean:
                {
                    bool flag   = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                    bool value3 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
                    return(flag.CompareTo(value3));
                }

                case JTokenType.Date:
                {
                    if (objA is DateTime)
                    {
                        DateTime dateTime = Convert.ToDateTime(objA, CultureInfo.InvariantCulture);
                        DateTime value2   = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
                        return(dateTime.CompareTo(value2));
                    }
                    if (!(objB is DateTimeOffset))
                    {
                        throw new ArgumentException("Object must be of type DateTimeOffset.");
                    }
                    DateTimeOffset dateTimeOffset = (DateTimeOffset)objA;
                    DateTimeOffset other          = (DateTimeOffset)objB;
                    return(dateTimeOffset.CompareTo(other));
                }

                case JTokenType.Bytes:
                {
                    if (!(objB is byte[]))
                    {
                        throw new ArgumentException("Object must be of type byte[].");
                    }
                    byte[] array  = objA as byte[];
                    byte[] array2 = objB as byte[];
                    if (array == null)
                    {
                        return(-1);
                    }
                    if (array2 == null)
                    {
                        return(1);
                    }
                    return(MiscellaneousUtils.ByteArrayCompare(array, array2));
                }

                case JTokenType.Guid:
                {
                    if (!(objB is Guid))
                    {
                        throw new ArgumentException("Object must be of type Guid.");
                    }
                    Guid guid   = (Guid)objA;
                    Guid value4 = (Guid)objB;
                    return(guid.CompareTo(value4));
                }

                case JTokenType.Uri:
                {
                    if (!(objB is Uri))
                    {
                        throw new ArgumentException("Object must be of type Uri.");
                    }
                    Uri uri  = (Uri)objA;
                    Uri uri2 = (Uri)objB;
                    return(Comparer <string> .Default.Compare(uri.ToString(), uri2.ToString()));
                }

                case JTokenType.TimeSpan:
                {
                    if (!(objB is TimeSpan))
                    {
                        throw new ArgumentException("Object must be of type TimeSpan.");
                    }
                    TimeSpan timeSpan = (TimeSpan)objA;
                    TimeSpan value    = (TimeSpan)objB;
                    return(timeSpan.CompareTo(value));
                }

                default:
                    throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
                }
            }
            return(-1);
        }
예제 #6
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == objB)
            {
                return 0;
            }
            if (objB == null)
            {
                return 1;
            }
            if (objA == null)
            {
                return -1;
            }

            switch (valueType)
            {
                case JTokenType.Integer:
                {
#if HAVE_BIG_INTEGER
                    if (objA is BigInteger integerA)
                    {
                        return CompareBigInteger(integerA, objB);
                    }
                    if (objB is BigInteger integerB)
                    {
                        return -CompareBigInteger(integerB, objA);
                    }
#endif
                    if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                    {
                        return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture));
                    }
                    else if (objA is float || objB is float || objA is double || objB is double)
                    {
                        return CompareFloat(objA, objB);
                    }
                    else
                    {
                        return Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture));
                    }
                }
                case JTokenType.Float:
                {
#if HAVE_BIG_INTEGER
                    if (objA is BigInteger integerA)
                    {
                        return CompareBigInteger(integerA, objB);
                    }
                    if (objB is BigInteger integerB)
                    {
                        return -CompareBigInteger(integerB, objA);
                    }
#endif
                    if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                    {
                        return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture));
                    }
                    return CompareFloat(objA, objB);
                }
                case JTokenType.Comment:
                case JTokenType.String:
                case JTokenType.Raw:
                    string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
                    string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);

                    return string.CompareOrdinal(s1, s2);
                case JTokenType.Boolean:
                    bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                    bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);

                    return b1.CompareTo(b2);
                case JTokenType.Date:
#if HAVE_DATE_TIME_OFFSET
                    if (objA is DateTime dateA)
                    {
#else
                        DateTime dateA = (DateTime)objA;
#endif
                        DateTime dateB;

#if HAVE_DATE_TIME_OFFSET
                        if (objB is DateTimeOffset offsetB)
                        {
                            dateB = offsetB.DateTime;
                        }
                        else
#endif
                        {
                            dateB = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
                        }

                        return dateA.CompareTo(dateB);
#if HAVE_DATE_TIME_OFFSET
                    }
                    else
                    {
                        DateTimeOffset offsetA = (DateTimeOffset)objA;
                        if (!(objB is DateTimeOffset offsetB))
                        {
                            offsetB = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
                        }

                        return offsetA.CompareTo(offsetB);
                    }
#endif
                case JTokenType.Bytes:
                    if (!(objB is byte[] bytesB))
                    {
                        throw new ArgumentException("Object must be of type byte[].");
                    }

                    byte[] bytesA = objA as byte[];
                    Debug.Assert(bytesA != null);

                    return MiscellaneousUtils.ByteArrayCompare(bytesA, bytesB);
                case JTokenType.Guid:
                    if (!(objB is Guid))
                    {
                        throw new ArgumentException("Object must be of type Guid.");
                    }

                    Guid guid1 = (Guid)objA;
                    Guid guid2 = (Guid)objB;

                    return guid1.CompareTo(guid2);
                case JTokenType.Uri:
                    Uri uri2 = objB as Uri;
                    if (uri2 == null)
                    {
                        throw new ArgumentException("Object must be of type Uri.");
                    }

                    Uri uri1 = (Uri)objA;

                    return Comparer<string>.Default.Compare(uri1.ToString(), uri2.ToString());
                case JTokenType.TimeSpan:
                    if (!(objB is TimeSpan))
                    {
                        throw new ArgumentException("Object must be of type TimeSpan.");
                    }

                    TimeSpan ts1 = (TimeSpan)objA;
                    TimeSpan ts2 = (TimeSpan)objB;

                    return ts1.CompareTo(ts2);
                default:
                    throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(valueType), valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }
예제 #7
0
파일: JValue.cs 프로젝트: zha0/Cerberus
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == objB)
            {
                return(0);
            }
            if (objB == null)
            {
                return(1);
            }
            if (objA == null)
            {
                return(-1);
            }
            switch (valueType)
            {
            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
            {
                string strA = Convert.ToString(objA, CultureInfo.InvariantCulture);
                string strB = Convert.ToString(objB, CultureInfo.InvariantCulture);
                return(string.CompareOrdinal(strA, strB));
            }

            case JTokenType.Integer:
                if (objA is System.Numerics.BigInteger)
                {
                    System.Numerics.BigInteger i = (System.Numerics.BigInteger)objA;
                    return(JValue.CompareBigInteger(i, objB));
                }
                if (objB is System.Numerics.BigInteger)
                {
                    System.Numerics.BigInteger i2 = (System.Numerics.BigInteger)objB;
                    return(-JValue.CompareBigInteger(i2, objA));
                }
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(JValue.CompareFloat(objA, objB));
                }
                return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));

            case JTokenType.Float:
                if (objA is System.Numerics.BigInteger)
                {
                    System.Numerics.BigInteger i3 = (System.Numerics.BigInteger)objA;
                    return(JValue.CompareBigInteger(i3, objB));
                }
                if (objB is System.Numerics.BigInteger)
                {
                    System.Numerics.BigInteger i4 = (System.Numerics.BigInteger)objB;
                    return(-JValue.CompareBigInteger(i4, objA));
                }
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                return(JValue.CompareFloat(objA, objB));

            case JTokenType.Boolean:
            {
                bool flag  = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool value = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
                return(flag.CompareTo(value));
            }

            case JTokenType.Date:
            {
                if (objA is DateTime)
                {
                    DateTime dateTime = (DateTime)objA;
                    DateTime value2;
                    if (objB is DateTimeOffset)
                    {
                        value2 = ((DateTimeOffset)objB).DateTime;
                    }
                    else
                    {
                        value2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
                    }
                    return(dateTime.CompareTo(value2));
                }
                DateTimeOffset dateTimeOffset = (DateTimeOffset)objA;
                DateTimeOffset other;
                if (objB is DateTimeOffset)
                {
                    other = (DateTimeOffset)objB;
                }
                else
                {
                    other = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
                }
                return(dateTimeOffset.CompareTo(other));
            }

            case JTokenType.Bytes:
            {
                byte[] array = objB as byte[];
                if (array == null)
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }
                return(MiscellaneousUtils.ByteArrayCompare(objA as byte[], array));
            }

            case JTokenType.Guid:
            {
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }
                Guid guid   = (Guid)objA;
                Guid value3 = (Guid)objB;
                return(guid.CompareTo(value3));
            }

            case JTokenType.Uri:
            {
                Uri uri = objB as Uri;
                if (uri == null)
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }
                Uri uri2 = (Uri)objA;
                return(Comparer <string> .Default.Compare(uri2.ToString(), uri.ToString()));
            }

            case JTokenType.TimeSpan:
            {
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }
                TimeSpan timeSpan = (TimeSpan)objA;
                TimeSpan value4   = (TimeSpan)objB;
                return(timeSpan.CompareTo(value4));
            }
            }
            throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
        }
예제 #8
0
        private static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA == null && objB != null)
            {
                return(-1);
            }

            switch (valueType)
            {
            case JTokenType.Integer:
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                else if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(CompareFloat(objA, objB));
                }
                else
                {
                    return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));
                }

            case JTokenType.Float:
                return(CompareFloat(objA, objB));

            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
                string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);

                return(string.CompareOrdinal(s1, s2));

            case JTokenType.Boolean:
                bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);

                return(b1.CompareTo(b2));

            case JTokenType.Date:
                if (objA is DateTime)
                {
                    DateTime date1 = Convert.ToDateTime(objA, CultureInfo.InvariantCulture);
                    DateTime date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);

                    return(date1.CompareTo(date2));
                }
                else
                {
                    if (!(objB is DateTimeOffset))
                    {
                        throw new ArgumentException("Object must be of type DateTimeOffset.");
                    }

                    DateTimeOffset date1 = (DateTimeOffset)objA;
                    DateTimeOffset date2 = (DateTimeOffset)objB;

                    return(date1.CompareTo(date2));
                }

            case JTokenType.Bytes:
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }

                byte[] bytes1 = objA as byte[];
                byte[] bytes2 = objB as byte[];
                if (bytes1 == null)
                {
                    return(-1);
                }
                if (bytes2 == null)
                {
                    return(1);
                }

                return(MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2));

            case JTokenType.Guid:
                if (!(objB is Guid))
                {
                    Guid guid;
                    if (Guid.TryParse((string)objB, out guid) == false)
                    {
                        throw new ArgumentException("Object must be of type Guid.");
                    }
                    objB = guid;
                }

                Guid guid1 = (Guid)objA;
                Guid guid2 = (Guid)objB;

                return(guid1.CompareTo(guid2));

            case JTokenType.Uri:
                if (objB is string)
                {
                    objB = new Uri((string)objB);
                }

                if (!(objB is Uri))
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }

                Uri uri1 = (Uri)objA;
                Uri uri2 = (Uri)objB;

                return(Comparer <string> .Default.Compare(uri1.ToString(), uri2.ToString()));

            case JTokenType.TimeSpan:
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }

                TimeSpan ts1 = (TimeSpan)objA;
                TimeSpan ts2 = (TimeSpan)objB;

                return(ts1.CompareTo(ts2));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }
예제 #9
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            DateTime time;
            DateTime dateTime;

            if ((objA == null) && (objB == null))
            {
                return(0);
            }
            if ((objA != null) && (objB == null))
            {
                return(1);
            }
            if ((objA == null) && (objB != null))
            {
                return(-1);
            }
            switch (valueType)
            {
            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                return(string.CompareOrdinal(Convert.ToString(objA, CultureInfo.InvariantCulture), Convert.ToString(objB, CultureInfo.InvariantCulture)));

            case JTokenType.Integer:
                switch (objA)
                {
                case (BigInteger _):
                    return(CompareBigInteger((BigInteger)objA, objB));

                    break;
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
                if (((objA is ulong) || (objB is ulong)) || ((objA is decimal) || (objB is decimal)))
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                if (((objA is float) || (objB is float)) || ((objA is double) || (objB is double)))
                {
                    return(CompareFloat(objA, objB));
                }
                return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));

            case JTokenType.Float:
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
                return(CompareFloat(objA, objB));

            case JTokenType.Boolean:
            {
                bool flag  = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool flag2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
                return(flag.CompareTo(flag2));
            }

            case JTokenType.Date:
            {
                if (!(objA is DateTime))
                {
                    DateTimeOffset offset3;
                    DateTimeOffset offset2 = (DateTimeOffset)objA;
                    if (objB is DateTimeOffset)
                    {
                        offset3 = (DateTimeOffset)objB;
                    }
                    else
                    {
                        offset3 = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
                    }
                    return(offset2.CompareTo(offset3));
                }
                time = (DateTime)objA;
                if (!(objB is DateTimeOffset))
                {
                    dateTime = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
                    break;
                }
                DateTimeOffset offset = (DateTimeOffset)objB;
                dateTime = offset.DateTime;
                break;
            }

            case JTokenType.Bytes:
            {
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }
                byte[] buffer  = objA as byte[];
                byte[] buffer2 = objB as byte[];
                if (buffer == null)
                {
                    return(-1);
                }
                if (buffer2 == null)
                {
                    return(1);
                }
                return(MiscellaneousUtils.ByteArrayCompare(buffer, buffer2));
            }

            case JTokenType.Guid:
            {
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }
                Guid guid  = (Guid)objA;
                Guid guid2 = (Guid)objB;
                return(guid.CompareTo(guid2));
            }

            case JTokenType.Uri:
            {
                if (!(objB is Uri))
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }
                Uri uri  = (Uri)objA;
                Uri uri2 = (Uri)objB;
                return(Comparer <string> .Default.Compare(uri.ToString(), uri2.ToString()));
            }

            case JTokenType.TimeSpan:
            {
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }
                TimeSpan span  = (TimeSpan)objA;
                TimeSpan span2 = (TimeSpan)objB;
                return(span.CompareTo(span2));
            }

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
            return(time.CompareTo(dateTime));
        }
예제 #10
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA == null)
            {
                return(-1);
            }

            switch (valueType)
            {
            case JTokenType.Integer:
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(CompareFloat(objA, objB));
                }
                return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));

            case JTokenType.Float:
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
                return(CompareFloat(objA, objB));

            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                var s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
                var s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);
                return(string.CompareOrdinal(s1, s2));

            case JTokenType.Boolean:
                var b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                var b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
                return(b1.CompareTo(b2));

            case JTokenType.Date:
                if (objA is DateTime)
                {
                    var date1 = (DateTime)objA;
                    var date2 = objB is DateTimeOffset ? ((DateTimeOffset)objB).DateTime : Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
                    return(date1.CompareTo(date2));
                }
                else
                {
                    var date1 = (DateTimeOffset)objA;
                    var date2 = objB is DateTimeOffset ? (DateTimeOffset)objB : new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
                    return(date1.CompareTo(date2));
                }

            case JTokenType.Bytes:
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }
                var bytes1 = objA as byte[];
                var bytes2 = objB as byte[];
                if (bytes1 == null)
                {
                    return(-1);
                }
                return(MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2));

            case JTokenType.Guid:
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }
                var guid1 = (Guid)objA;
                var guid2 = (Guid)objB;
                return(guid1.CompareTo(guid2));

            case JTokenType.Uri:
                if (!(objB is Uri))
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }
                var uri1 = (Uri)objA;
                var uri2 = (Uri)objB;
                return(Comparer <string> .Default.Compare(uri1.ToString(), uri2.ToString()));

            case JTokenType.TimeSpan:
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }
                var ts1 = (TimeSpan)objA;
                var ts2 = (TimeSpan)objB;
                return(ts1.CompareTo(ts2));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }
예제 #11
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA == null && objB != null)
            {
                return(-1);
            }
            switch (valueType)
            {
            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                return(string.CompareOrdinal(Convert.ToString(objA, (IFormatProvider)CultureInfo.InvariantCulture), Convert.ToString(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Integer:
                if (objA is ulong || objB is ulong || (objA is Decimal || objB is Decimal))
                {
                    return(Convert.ToDecimal(objA, (IFormatProvider)CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, (IFormatProvider)CultureInfo.InvariantCulture)));
                }
                return(objA is float || objB is float || (objA is double || objB is double) ? JValue.CompareFloat(objA, objB) : Convert.ToInt64(objA, (IFormatProvider)CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Float:
                return(JValue.CompareFloat(objA, objB));

            case JTokenType.Boolean:
                return(Convert.ToBoolean(objA, (IFormatProvider)CultureInfo.InvariantCulture).CompareTo(Convert.ToBoolean(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Date:
                if (objA is DateTime dateTime)
                {
                    DateTime dateTime = !(objB is DateTimeOffset dateTimeOffset2) ? Convert.ToDateTime(objB, (IFormatProvider)CultureInfo.InvariantCulture) : dateTimeOffset2.DateTime;
                    return(dateTime.CompareTo(dateTime));
                }
                DateTimeOffset dateTimeOffset1 = (DateTimeOffset)objA;
                if (!(objB is DateTimeOffset other))
                {
                    other = new DateTimeOffset(Convert.ToDateTime(objB, (IFormatProvider)CultureInfo.InvariantCulture));
                }
                return(dateTimeOffset1.CompareTo(other));

            case JTokenType.Bytes:
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }
                byte[] a1 = objA as byte[];
                byte[] a2 = objB as byte[];
                if (a1 == null)
                {
                    return(-1);
                }
                return(a2 == null ? 1 : MiscellaneousUtils.ByteArrayCompare(a1, a2));

            case JTokenType.Guid:
                if (!(objB is Guid guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }
                return(((Guid)objA).CompareTo(guid));

            case JTokenType.Uri:
                if ((object)(objB as Uri) == null)
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }
                return(Comparer <string> .Default.Compare(((Uri)objA).ToString(), ((Uri)objB).ToString()));

            case JTokenType.TimeSpan:
                if (!(objB is TimeSpan timeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }
                return(((TimeSpan)objA).CompareTo(timeSpan));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(valueType), (object)valueType, "Unexpected value type: {0}".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)valueType));
            }
        }
예제 #12
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            DateTime       dateTime;
            DateTimeOffset dateTimeOffset;

            if (objA == null && objB == null)
            {
                return(0);
            }
            if (objA != null && objB == null)
            {
                return(1);
            }
            if (objA == null && objB != null)
            {
                return(-1);
            }
            switch (valueType)
            {
            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
            {
                string str  = Convert.ToString(objA, CultureInfo.InvariantCulture);
                string str1 = Convert.ToString(objB, CultureInfo.InvariantCulture);
                return(string.CompareOrdinal(str, str1));
            }

            case JTokenType.Integer:
            {
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    decimal num = Convert.ToDecimal(objA, CultureInfo.InvariantCulture);
                    return(num.CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(JValue.CompareFloat(objA, objB));
                }
                long num1 = Convert.ToInt64(objA, CultureInfo.InvariantCulture);
                return(num1.CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));
            }

            case JTokenType.Float:
            {
                return(JValue.CompareFloat(objA, objB));
            }

            case JTokenType.Boolean:
            {
                bool flag  = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool flag1 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
                return(flag.CompareTo(flag1));
            }

            case JTokenType.Null:
            case JTokenType.Undefined:
            {
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }

            case JTokenType.Date:
            {
                if (!(objA is DateTime))
                {
                    DateTimeOffset dateTimeOffset1 = (DateTimeOffset)objA;
                    dateTimeOffset = (!(objB is DateTimeOffset) ? new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture)) : (DateTimeOffset)objB);
                    return(dateTimeOffset1.CompareTo(dateTimeOffset));
                }
                DateTime dateTime1 = (DateTime)objA;
                dateTime = (!(objB is DateTimeOffset) ? Convert.ToDateTime(objB, CultureInfo.InvariantCulture) : ((DateTimeOffset)objB).DateTime);
                return(dateTime1.CompareTo(dateTime));
            }

            case JTokenType.Bytes:
            {
                if (!(objB is byte[]))
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }
                byte[] numArray  = objA as byte[];
                byte[] numArray1 = objB as byte[];
                if (numArray == null)
                {
                    return(-1);
                }
                if (numArray1 == null)
                {
                    return(1);
                }
                return(MiscellaneousUtils.ByteArrayCompare(numArray, numArray1));
            }

            case JTokenType.Guid:
            {
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }
                return(((Guid)objA).CompareTo((Guid)objB));
            }

            case JTokenType.Uri:
            {
                if (!(objB is Uri))
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }
                Uri uri  = (Uri)objA;
                Uri uri1 = (Uri)objB;
                return(Comparer <string> .Default.Compare(uri.ToString(), uri1.ToString()));
            }

            case JTokenType.TimeSpan:
            {
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }
                return(((TimeSpan)objA).CompareTo((TimeSpan)objB));
            }

            default:
            {
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
            }
        }
예제 #13
0
파일: JValue.cs 프로젝트: cs130-w21/13
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == objB)
            {
                return(0);
            }
            if (objB == null)
            {
                return(1);
            }
            if (objA == null)
            {
                return(-1);
            }
            switch (valueType)
            {
            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                return(string.CompareOrdinal(Convert.ToString(objA, (IFormatProvider)CultureInfo.InvariantCulture), Convert.ToString(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Integer:
                if (objA is ulong || objB is ulong || (objA is Decimal || objB is Decimal))
                {
                    return(Convert.ToDecimal(objA, (IFormatProvider)CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, (IFormatProvider)CultureInfo.InvariantCulture)));
                }
                if (objA is float || objB is float || (objA is double || objB is double))
                {
                    return(JValue.CompareFloat(objA, objB));
                }
                return(Convert.ToInt64(objA, (IFormatProvider)CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Float:
                return(JValue.CompareFloat(objA, objB));

            case JTokenType.Boolean:
                return(Convert.ToBoolean(objA, (IFormatProvider)CultureInfo.InvariantCulture).CompareTo(Convert.ToBoolean(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Date:
                return(((DateTime)objA).CompareTo(Convert.ToDateTime(objB, (IFormatProvider)CultureInfo.InvariantCulture)));

            case JTokenType.Bytes:
                byte[] a2 = objB as byte[];
                if (a2 == null)
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }
                return(MiscellaneousUtils.ByteArrayCompare(objA as byte[], a2));

            case JTokenType.Guid:
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }
                return(((Guid)objA).CompareTo((Guid)objB));

            case JTokenType.Uri:
                Uri uri = objB as Uri;
                if (uri == (Uri)null)
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }
                return(Comparer <string> .Default.Compare(((Uri)objA).ToString(), uri.ToString()));

            case JTokenType.TimeSpan:
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }
                return(((TimeSpan)objA).CompareTo((TimeSpan)objB));

            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(valueType), (object)valueType, "Unexpected value type: {0}".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)valueType));
            }
        }
예제 #14
0
        internal static int Compare(JTokenType valueType, object objA, object objB)
        {
            if (objA == objB)
            {
                return(0);
            }
            if (objB == null)
            {
                return(1);
            }
            if (objA == null)
            {
                return(-1);
            }

            switch (valueType)
            {
            case JTokenType.Integer:
#if HAVE_BIG_INTEGER
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
#endif
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                else if (objA is float || objB is float || objA is double || objB is double)
                {
                    return(CompareFloat(objA, objB));
                }
                else
                {
                    return(Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture)));
                }

            case JTokenType.Float:
#if HAVE_BIG_INTEGER
                if (objA is BigInteger)
                {
                    return(CompareBigInteger((BigInteger)objA, objB));
                }
                if (objB is BigInteger)
                {
                    return(-CompareBigInteger((BigInteger)objB, objA));
                }
#endif
                if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
                {
                    return(Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)));
                }
                return(CompareFloat(objA, objB));

            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
                string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
                string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);

                return(string.CompareOrdinal(s1, s2));

            case JTokenType.Boolean:
                bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
                bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);

                return(b1.CompareTo(b2));

            case JTokenType.Date:
#if HAVE_DATE_TIME_OFFSET
                if (objA is DateTime)
                {
#endif
                DateTime date1 = (DateTime)objA;
                DateTime date2;

#if HAVE_DATE_TIME_OFFSET
                if (objB is DateTimeOffset)
                {
                    date2 = ((DateTimeOffset)objB).DateTime;
                }
                else
#endif
                {
                    date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
                }

                return(date1.CompareTo(date2));

#if HAVE_DATE_TIME_OFFSET
            }
            else
            {
                DateTimeOffset date1 = (DateTimeOffset)objA;
                DateTimeOffset date2;

                if (objB is DateTimeOffset)
                {
                    date2 = (DateTimeOffset)objB;
                }
                else
                {
                    date2 = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
                }

                return(date1.CompareTo(date2));
            }
#endif
            case JTokenType.Bytes:
                byte[] bytes2 = objB as byte[];
                if (bytes2 == null)
                {
                    throw new ArgumentException("Object must be of type byte[].");
                }

                byte[] bytes1 = objA as byte[];
                Debug.Assert(bytes1 != null);

                return(MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2));

            case JTokenType.Guid:
                if (!(objB is Guid))
                {
                    throw new ArgumentException("Object must be of type Guid.");
                }

                Guid guid1 = (Guid)objA;
                Guid guid2 = (Guid)objB;

                return(guid1.CompareTo(guid2));

            case JTokenType.Uri:
                Uri uri2 = objB as Uri;
                if (uri2 == null)
                {
                    throw new ArgumentException("Object must be of type Uri.");
                }

                Uri uri1 = (Uri)objA;

                return(Comparer <string> .Default.Compare(uri1.ToString(), uri2.ToString()));

            case JTokenType.TimeSpan:
                if (!(objB is TimeSpan))
                {
                    throw new ArgumentException("Object must be of type TimeSpan.");
                }

                TimeSpan ts1 = (TimeSpan)objA;
                TimeSpan ts2 = (TimeSpan)objB;

                return(ts1.CompareTo(ts2));

#if (JSON_SmallDecSupport)
            case JTokenType.SmallDec:
                SmallDec Value01 = (SmallDec)objA;
                SmallDec Value02 = (SmallDec)objB;
                return(Value01.CompareTo(Value02));
#endif
            default:
                throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(valueType), valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType));
            }
        }