internal static Type EnsureGenericRuntimeType(Type p) { Type t = EnsureBoxedType(p); if (t != p) { return(t); } return(NullableReflection.GetUnderlyingTypeForMarked(p) ?? GenericInstanceFactory.GetGenericTypeDefinition(p) ?? p); }
/// <summary> /// Create an instance of the given type using the best matching constructor. /// </summary> public static object CreateInstance(Type type, params object[] args) { if (NullableReflection.TreatAsSystemNullableT(type)) { return(null); } var genericInstance = GenericInstanceFactory.CreateGenericInstance(type, args); if (genericInstance != null) { return(genericInstance); } var constructor = GetBestMatchingConstructor(type, args); return(constructor.NewInstance(args)); }
/// <summary> /// Create an instance of the given type using it's default constructor. /// </summary> public static object CreateInstance(Type type) { if (NullableReflection.TreatAsSystemNullableT(type)) { return(null); } var genericInstance = GenericInstanceFactory.CreateGenericInstance(type); if (genericInstance != null) { return(genericInstance); } if (type.IsPrimitive) { return(TypeHelper.GetPrimitiveDefault(type)); } return(type.NewInstance()); }
/// <summary> /// Create an instance of the given type T using it's default constructor. /// </summary> public static T CreateInstance <T>() { var type = typeof(T); if (NullableReflection.TreatAsSystemNullableT(type)) { return(default(T)); } var genericInstance = GenericInstanceFactory.CreateGenericInstance(type); if (genericInstance != null) { return((T)genericInstance); } if (type.IsPrimitive) { return((T)TypeHelper.GetPrimitiveDefault(type)); } return((T)type.NewInstance()); }
public static Type GetUnderlyingType(Type nullableType) { return(NullableReflection.GetUnderlyingType(nullableType)); }