Generics and Reflection (C# Programming Guide)
Because the Common Language Runtime (CLR) has access to generic type information at run time, you can use reflection to obtain information about generic types in the same way as for non-generic types. For more information, see Generics in the Run Time (C# Programming Guide).
In the .NET Framework 2.0 several new members are added to the Type class to enable run-time information for generic types. See the documentation on these classes for more information on how to use these methods and properties. The System.Reflection.Emit namespace also contains new members that support generics. See How to: Define a Generic Type with Reflection Emit.
For a list of the invariant conditions for terms used in generic reflection, see the IsGenericType property remarks.
System.Type Member Name |
Description |
---|---|
Returns true if a type is generic. |
|
Returns an array of Type objects that represent the type arguments supplied for a constructed type, or the type parameters of a generic type definition. |
|
Returns the underlying generic type definition for the current constructed type. |
|
Returns an array of Type objects that represent the constraints on the current generic type parameter. |
|
Returns true if the type or any of its enclosing types or methods contain type parameters for which specific types have not been supplied. |
|
Gets a combination of GenericParameterAttributes flags that describe the special constraints of the current generic type parameter. |
|
For a Type object that represents a type parameter, gets the position of the type parameter in the type parameter list of the generic type definition or generic method definition that declared the type parameter. |
|
Gets a value that indicates whether the current Type represents a type parameter of a generic type or method definition. |
|
Gets a value that indicates whether the current Type represents a generic type definition, from which other generic types can be constructed. Returns true if the type represents the definition of a generic type. |
|
Returns the generic method that defined the current generic type parameter, or null if the type parameter was not defined by a generic method. |
|
Substitutes the elements of an array of types for the type parameters of the current generic type definition, and returns a Type object representing the resulting constructed type. |
In addition, new members are added to the MethodInfo class to enable run-time information for generic methods. See the IsGenericMethod property remarks for a list of invariant conditions for terms used to reflect on generic methods.
System.Reflection.MemberInfo Member Name |
Description |
---|---|
Returns true if a method is generic. |
|
Returns an array of Type objects that represent the type arguments of a constructed generic method or the type parameters of a generic method definition. |
|
Returns the underlying generic method definition for the current constructed method. |
|
Returns true if the method or any of its enclosing types contain any type parameters for which specific types have not been supplied. |
|
Returns true if the current MethodInfo represents the definition of a generic method. |
|
Substitutes the elements of an array of types for the type parameters of the current generic method definition, and returns a MethodInfo object representing the resulting constructed method. |
See Also
Reference
Generics (C# Programming Guide)