/// <summary> /// Gets the nullable type that corresponds to the given type. /// </summary> public static Type GetNullableType(Type type) { if (!type.GetTypeInfo().IsValueType) { return(type); } if (NullableInfoMap.TryGetValue(type, out var result)) { return(result.NullableType); } else { return(null); } }
/// <summary> /// Gets the default value for a specified type. /// </summary> public static object GetDefaultValue(Type type) { if (type == null) { return(null); } if (!type.GetTypeInfo().IsValueType) { return(null); } if (NullableInfoMap.TryGetValue(type, out var result)) { return(result.DefaultValue); } else { return(Activator.CreateInstance(type)); } }