Beispiel #1
0
        public static eDataType GetType(Type type)
        {
            while (type != null)
            {
                if (type.IsEnum)
                {
                    return(eDataType.Int32);
                }

                if (type.IsNullableGeneric())
                {
                    type = type.GetGenericArguments()[0];
                }

                if (type.IsEnum)
                {
                    return(eDataType.Int32);
                }

                if (dicTypeToDataType.ContainsKey(type))
                {
                    return(dicTypeToDataType[type]);
                }

                type = type.BaseType;
            }

            throw new ArgumentNullException("type");
        }
Beispiel #2
0
        public static Type GetGenericTypeInNullable(this Type source)
        {
            if (!source.IsNullableGeneric())
            {
                return(null);
            }

            return(source.GetGenericArguments()[0]);
        }
Beispiel #3
0
        public static object GetDefaultValueNoNull(this Type source)
        {
            object value = null;

            if (source == typeof(string))
            {
                value = string.Empty;
            }
            else if (source.IsNullableGeneric())
            {
                value = Activator.CreateInstance(source.GetGenericTypeInNullable());
            }
            else
            {
                value = Activator.CreateInstance(source);
            }

            return(value);
        }
Beispiel #4
0
 public static bool IsNullable(this Type source)
 {
     return(!source.IsValueType || source.IsNullableGeneric());
 }