Gets the position of the type parameter in the type parameter list of the generic type or method that declared the parameter, when the Type object represents a type parameter of a generic type or a generic method.
Assembly: mscorlib (in mscorlib.dll)
The property returns the position of a type parameter in the parameter list of the generic type definition or generic method definition where the type parameter was originally defined. The DeclaringType and DeclaringMethod properties identify the generic type or method definition:
If the DeclaringMethod property returns a MethodInfo, that MethodInfo represents a generic method definition, and the current Type object represents a type parameter of that generic method definition.
If the DeclaringMethod property returns a null reference (Nothing in Visual Basic), then the DeclaringType property always returns a Type object representing a generic type definition, and the current Type object represents a type parameter of that generic type definition.
To provide the correct context for the value of the property, it is necessary to identify the generic type or method a type parameter belongs to. For example, consider the return value of the generic method GetSomething in the following code:
The type returned by GetSomething depends on the type arguments supplied to class A and to GetSomething itself. You can obtain a MethodInfo for GetSomething, and from that you can obtain the return type. When you examine the type parameters of the return type, returns 0 for both. The position of V is 0 because V is the first type parameter in the type parameter list for class A. The position of X is 0 because X is the first type parameter in the type parameter list for GetSomething.
Calling the property causes an exception if the current Type does not represent a type parameter. When you examine the type arguments of an open constructed type, use the IsGenericParameter property to tell which are type parameters and which are types. The IsGenericParameter property returns true for a type parameter; you can then use the method to obtain its position and use the DeclaringMethod and DeclaringType properties to determine the generic method or type definition that defines it.
The following example defines a generic class with two type parameters and defines a second generic class that derives from the first class. The derived class's base class has two type arguments: the first is Int32, and the second is a type parameter of the derived type. The example displays information about these generic classes, including the positions reported by the property.