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"); }
public static Type GetGenericTypeInNullable(this Type source) { if (!source.IsNullableGeneric()) { return(null); } return(source.GetGenericArguments()[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); }
public static bool IsNullable(this Type source) { return(!source.IsValueType || source.IsNullableGeneric()); }