IsGenericType tells you that this instance of System.Type represents a generic type with all its type parameters specified. For example, List<int> is a generic type.
IsGenericTypeDefinition, on the other hand, tells you that this instance of System.Type represents a definition from which generic types can be constructed by supplying type arguments for its type parameters. For example, List<> is a generic type definition.
You can get a generic type definition of a generic type by calling GetGenericTypeDefinition:
var listInt = typeof(List<int>); var typeDef = listInt.GetGenericTypeDefinition(); // gives typeof(List<>)
You can make a generic type from a generic type definition by providing it with type arguments to MakeGenericType:
var listDef = typeof(List<>); var listStr = listDef.MakeGenericType(typeof(string));
IsGenericType:
typeof(DateTime).IsGenericType : false
typeof(List<int>).IsGenericType: true
typeof(Dictionary<,>).IsGenericType:true
IsGenericTypeDefinition:
typeof(List<int>).IsGenericTypeDefintion : false
typeof(List<>).IsGenericTypeDefinition :true
IsGenericTypeDefinition : 获取一个值,该值指示当前 Type 是否表示可以用来构造其他泛型类型的泛型类型定义。
也就是说表明 这个 type 是否可以用于构建泛型定义
比如 List<> 可以通过反射构建出 List,List
-
var typeList = typeof(List<>);
-
Type typeDataList = typeList.MakeGenericType( typeof(DateTime)); //通过List<>构建出List<DateTime>