Пример #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: 0x06001773 RID: 6003 RVA: 0x0006EE5A File Offset: 0x0006D05A
 public static Type EnsureNotNullableType(Type t)
 {
     if (!Class_514.IsNullableType(t))
     {
         return(t);
     }
     return(Nullable.GetUnderlyingType(t));
 }
Пример #3
0
 // Token: 0x06001771 RID: 6001 RVA: 0x0006EE0B File Offset: 0x0006D00B
 public static bool IsNullable(Type t)
 {
     Class_517.ArgumentNotNull(t, "t");
     return(!t.IsValueType || Class_514.IsNullableType(t));
 }
Пример #4
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);
            }
        }
Пример #5
0
 // Token: 0x060016E0 RID: 5856 RVA: 0x0006C110 File Offset: 0x0006A310
 private static bool pmethod_4099(object obje_0)
 {
     return(obje_0 is T || (obje_0 == null && (!typeof(T).IsValueType || Class_514.IsNullableType(typeof(T)))));
 }