Exemple #1
0
        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);
        }
Exemple #2
0
 /// <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);
 }
Exemple #3
0
        /// <summary>
        /// will never return null
        /// </summary>
        public static string GetName(Type type)
        {
            var baseType = GenericInstanceFactory.GetGenericTypeDefinition(type) ?? type;

            return(baseType.GetSimpleName().Replace(GenericTickChar, '`'));
        }