public static Type GetGenericTypeDefinition(Type type) { // emulate Nullable<T> if (NullableReflection.TreatAsSystemNullableT(type)) { return(typeof(Nullable <>)); } // is generic proxy? var ret = GenericInstanceFactory.GetGenericTypeDefinition(type); if (ret != null) { return(ret); } // is generic type? just return itself. if (!IsGenericType(type)) { ThrowHelper.ThrowInvalidOperationException(ExceptionResource.NotAGenericType); } return(type); }
/// <summary> /// return the generic type definition if, any or type itself. /// </summary> /// <param name="type"></param> /// <returns></returns> public static Type EnsureTypeDef(Type type) { return(GenericInstanceFactory.GetGenericTypeDefinition(type) ?? type); }
/// <summary> /// will never return null /// </summary> public static string GetName(Type type) { var baseType = GenericInstanceFactory.GetGenericTypeDefinition(type) ?? type; return(baseType.GetSimpleName().Replace(GenericTickChar, '`')); }