示例#1
0
        // Token: 0x060016AE RID: 5806 RVA: 0x0006AC24 File Offset: 0x00068E24
        public static Class_496 GetTypeCode(Type t, out bool isEnum)
        {
            Class_496 result;

            if (Class_499.TypeCodeMap.TryGetValue(t, out result))
            {
                isEnum = false;
                return(result);
            }
            if (t.IsEnum)
            {
                isEnum = true;
                return(Class_499.GetTypeCode(Enum.GetUnderlyingType(t)));
            }
            if (Class_514.IsNullableType(t))
            {
                Type underlyingType = Nullable.GetUnderlyingType(t);
                if (underlyingType.IsEnum)
                {
                    Type t2 = typeof(Nullable <>).MakeGenericType(new Type[]
                    {
                        Enum.GetUnderlyingType(underlyingType)
                    });
                    isEnum = true;
                    return(Class_499.GetTypeCode(t2));
                }
            }
            isEnum = false;
            return(Class_496.Object);
        }
示例#2
0
 // Token: 0x060016BA RID: 5818 RVA: 0x0006B450 File Offset: 0x00069650
 public static object ToValue(INullable nullableValue)
 {
     if (nullableValue == null)
     {
         return(null);
     }
     if (nullableValue is SqlInt32)
     {
         return(Class_499.ToValue((SqlInt32)nullableValue));
     }
     if (nullableValue is SqlInt64)
     {
         return(Class_499.ToValue((SqlInt64)nullableValue));
     }
     if (nullableValue is SqlBoolean)
     {
         return(Class_499.ToValue((SqlBoolean)nullableValue));
     }
     if (nullableValue is SqlString)
     {
         return(Class_499.ToValue((SqlString)nullableValue));
     }
     if (nullableValue is SqlDateTime)
     {
         return(Class_499.ToValue((SqlDateTime)nullableValue));
     }
     throw new ArgumentException("Unsupported INullable type: {0}".FormatWith(CultureInfo.InvariantCulture, nullableValue.GetType()));
 }
示例#3
0
 // Token: 0x060016BB RID: 5819 RVA: 0x0006B50C File Offset: 0x0006970C
 public static bool IsInteger(object value)
 {
     switch (Class_499.GetTypeCode(value.GetType()))
     {
     case Class_496.SByte:
     case Class_496.Int16:
     case Class_496.UInt16:
     case Class_496.Int32:
     case Class_496.Byte:
     case Class_496.UInt32:
     case Class_496.Int64:
     case Class_496.UInt64:
         return(true);
     }
     return(false);
 }
示例#4
0
        // Token: 0x060016B8 RID: 5816 RVA: 0x0006B364 File Offset: 0x00069564
        public static object ConvertOrCast(object initialValue, CultureInfo culture, Type targetType)
        {
            if (targetType == typeof(object))
            {
                return(initialValue);
            }
            if (initialValue == null && Class_514.IsNullable(targetType))
            {
                return(null);
            }
            object result;

            if (Class_499.TryConvert(initialValue, culture, targetType, out result))
            {
                return(result);
            }
            return(Class_499.EnsureTypeAssignable(initialValue, Class_514.GetObjectType(initialValue), targetType));
        }
示例#5
0
        // Token: 0x060016B5 RID: 5813 RVA: 0x0006AF78 File Offset: 0x00069178
        public static object Convert(object initialValue, CultureInfo culture, Type targetType)
        {
            object result;

            switch (Class_499.TryConvertInternal(initialValue, culture, targetType, out result))
            {
            case Class_499.ConvertResult.Success:
                return(result);

            case Class_499.ConvertResult.CannotConvertNull:
                throw new Exception("Can not convert null {0} into non-nullable {1}.".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType));

            case Class_499.ConvertResult.NotInstantiableType:
                throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), "targetType");

            case Class_499.ConvertResult.NoValidConversion:
                throw new InvalidOperationException("Can not convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType));

            default:
                throw new InvalidOperationException("Unexpected conversion result.");
            }
        }
示例#6
0
        // Token: 0x060016B6 RID: 5814 RVA: 0x0006B00C File Offset: 0x0006920C
        private static bool TryConvert(object initialValue, CultureInfo culture, Type targetType, out object value)
        {
            bool result;

            try
            {
                if (Class_499.TryConvertInternal(initialValue, culture, targetType, out value) == Class_499.ConvertResult.Success)
                {
                    result = true;
                }
                else
                {
                    value  = null;
                    result = false;
                }
            }
            catch
            {
                value  = null;
                result = false;
            }
            return(result);
        }
示例#7
0
 // Token: 0x0600175F RID: 5983 RVA: 0x0006E8FC File Offset: 0x0006CAFC
 public static bool ValueEquals(object objA, object objB)
 {
     if (objA == null && objB == null)
     {
         return(true);
     }
     if (objA != null && objB == null)
     {
         return(false);
     }
     if (objA == null && objB != null)
     {
         return(false);
     }
     if (!(objA.GetType() != objB.GetType()))
     {
         return(objA.Equals(objB));
     }
     if (Class_499.IsInteger(objA) && Class_499.IsInteger(objB))
     {
         return(Convert.ToDecimal(objA, CultureInfo.CurrentCulture).Equals(Convert.ToDecimal(objB, CultureInfo.CurrentCulture)));
     }
     return((objA is double || objA is float || objA is decimal) && (objB is double || objB is float || objB is decimal) && Class_511.ApproxEquals(Convert.ToDouble(objA, CultureInfo.CurrentCulture), Convert.ToDouble(objB, CultureInfo.CurrentCulture)));
 }
示例#8
0
        // Token: 0x06001792 RID: 6034 RVA: 0x0006FC5C File Offset: 0x0006DE5C
        public static object GetDefaultValue(Type type)
        {
            if (!type.IsValueType)
            {
                return(null);
            }
            Class_496 typeCode = Class_499.GetTypeCode(type);

            switch (typeCode)
            {
            case Class_496.Char:
            case Class_496.SByte:
            case Class_496.Int16:
            case Class_496.UInt16:
            case Class_496.Int32:
            case Class_496.Byte:
            case Class_496.UInt32:
                return(0);

            case Class_496.CharNullable:
            case Class_496.BooleanNullable:
            case Class_496.SByteNullable:
            case Class_496.Int16Nullable:
            case Class_496.UInt16Nullable:
            case Class_496.Int32Nullable:
            case Class_496.ByteNullable:
            case Class_496.UInt32Nullable:
            case Class_496.Int64Nullable:
            case Class_496.UInt64Nullable:
            case Class_496.SingleNullable:
            case Class_496.DoubleNullable:
            case Class_496.DateTimeNullable:
            case Class_496.DateTimeOffsetNullable:
            case Class_496.DecimalNullable:
                break;

            case Class_496.Boolean:
                return(false);

            case Class_496.Int64:
            case Class_496.UInt64:
                return(0L);

            case Class_496.Single:
                return(0f);

            case Class_496.Double:
                return(0.0);

            case Class_496.DateTime:
                return(default(DateTime));

            case Class_496.DateTimeOffset:
                return(default(DateTimeOffset));

            case Class_496.Decimal:
                return(0m);

            case Class_496.Guid:
                return(default(Guid));

            default:
                if (typeCode == Class_496.BigInteger)
                {
                    return(default(BigInteger));
                }
                break;
            }
            if (Class_514.IsNullable(type))
            {
                return(null);
            }
            return(Activator.CreateInstance(type));
        }
示例#9
0
        // Token: 0x060016B7 RID: 5815 RVA: 0x0006B054 File Offset: 0x00069254
        private static Class_499.ConvertResult TryConvertInternal(object initialValue, CultureInfo culture, Type targetType, out object value)
        {
            if (initialValue == null)
            {
                throw new ArgumentNullException("initialValue");
            }
            if (Class_514.IsNullableType(targetType))
            {
                targetType = Nullable.GetUnderlyingType(targetType);
            }
            Type type = initialValue.GetType();

            if (targetType == type)
            {
                value = initialValue;
                return(Class_499.ConvertResult.Success);
            }
            if (Class_499.IsConvertible(initialValue.GetType()) && Class_499.IsConvertible(targetType))
            {
                if (targetType.IsEnum)
                {
                    if (initialValue is string)
                    {
                        value = Enum.Parse(targetType, initialValue.ToString(), true);
                        return(Class_499.ConvertResult.Success);
                    }
                    if (Class_499.IsInteger(initialValue))
                    {
                        value = Enum.ToObject(targetType, initialValue);
                        return(Class_499.ConvertResult.Success);
                    }
                }
                value = System.Convert.ChangeType(initialValue, targetType, culture);
                return(Class_499.ConvertResult.Success);
            }
            if (initialValue is DateTime && targetType == typeof(DateTimeOffset))
            {
                value = new DateTimeOffset((DateTime)initialValue);
                return(Class_499.ConvertResult.Success);
            }
            if (initialValue is byte[] && targetType == typeof(Guid))
            {
                value = new Guid((byte[])initialValue);
                return(Class_499.ConvertResult.Success);
            }
            if (initialValue is Guid && targetType == typeof(byte[]))
            {
                value = ((Guid)initialValue).ToByteArray();
                return(Class_499.ConvertResult.Success);
            }
            if (initialValue is string)
            {
                if (targetType == typeof(Guid))
                {
                    value = new Guid((string)initialValue);
                    return(Class_499.ConvertResult.Success);
                }
                if (targetType == typeof(Uri))
                {
                    value = new Uri((string)initialValue, UriKind.RelativeOrAbsolute);
                    return(Class_499.ConvertResult.Success);
                }
                if (targetType == typeof(TimeSpan))
                {
                    value = Class_499.ParseTimeSpan((string)initialValue);
                    return(Class_499.ConvertResult.Success);
                }
                if (targetType == typeof(byte[]))
                {
                    value = System.Convert.FromBase64String((string)initialValue);
                    return(Class_499.ConvertResult.Success);
                }
                if (typeof(Type).IsAssignableFrom(targetType))
                {
                    value = Type.GetType((string)initialValue, true);
                    return(Class_499.ConvertResult.Success);
                }
            }
            if (targetType == typeof(BigInteger))
            {
                value = Class_499.ToBigInteger(initialValue);
                return(Class_499.ConvertResult.Success);
            }
            if (initialValue is BigInteger)
            {
                value = Class_499.FromBigInteger((BigInteger)initialValue, targetType);
                return(Class_499.ConvertResult.Success);
            }
            TypeConverter typeConverter = Class_470.GetTypeConverter(type);

            if (typeConverter != null && typeConverter.CanConvertTo(targetType))
            {
                value = typeConverter.ConvertTo(null, culture, initialValue, targetType);
                return(Class_499.ConvertResult.Success);
            }
            TypeConverter typeConverter2 = Class_470.GetTypeConverter(targetType);

            if (typeConverter2 != null && typeConverter2.CanConvertFrom(type))
            {
                value = typeConverter2.ConvertFrom(null, culture, initialValue);
                return(Class_499.ConvertResult.Success);
            }
            if (initialValue == DBNull.Value)
            {
                if (Class_514.IsNullable(targetType))
                {
                    value = Class_499.EnsureTypeAssignable(null, type, targetType);
                    return(Class_499.ConvertResult.Success);
                }
                value = null;
                return(Class_499.ConvertResult.CannotConvertNull);
            }
            else
            {
                if (initialValue is INullable)
                {
                    value = Class_499.EnsureTypeAssignable(Class_499.ToValue((INullable)initialValue), type, targetType);
                    return(Class_499.ConvertResult.Success);
                }
                if (targetType.IsInterface || targetType.IsGenericTypeDefinition || targetType.IsAbstract)
                {
                    value = null;
                    return(Class_499.ConvertResult.NotInstantiableType);
                }
                value = null;
                return(Class_499.ConvertResult.NoValidConversion);
            }
        }
示例#10
0
        // Token: 0x060016AD RID: 5805 RVA: 0x0006AC0C File Offset: 0x00068E0C
        public static Class_496 GetTypeCode(Type t)
        {
            bool flag;

            return(Class_499.GetTypeCode(t, out flag));
        }