Returns an array of Type objects that represent the type arguments of a generic method or the type parameters of a generic method definition.
An array of Type objects that represent the type arguments of a generic method or the type parameters of a generic method definition. Returns an empty array if the current method is not a generic method.
The elements of the returned array are in the order in which they appear in the list of type parameters for the generic method.
If the current method is a closed constructed method (that is, the MethodInfo.ContainsGenericParameters property returns false), the array returned by the MethodInfo.GetGenericArguments method contains the types that have been assigned to the generic type parameters of the generic method definition.
If the current method is a generic method definition, the array contains the type parameters.
If the current method is an open constructed method (that is, the MethodInfo.ContainsGenericParameters property returns true) in which specific types have been assigned to some type parameters and type parameters of enclosing generic types have been assigned to other type parameters, the array contains both types and type parameters. Use the Type.IsGenericParameter property to tell them apart. For a demonstration of this scenario, see the code example for the MethodInfo.ContainsGenericParameters property.
For a list of the invariant conditions for terms specific to generic methods, see the MethodInfo.IsGenericMethod property. For a list of the invariant conditions for other terms used in generic reflection, see the Type.IsGenericType property.
The following code shows how to get the type arguments of a generic method and display them. (It is part of a larger example for the method System.Reflection.MethodInfo.MakeGenericMethod.)
C# Example
// If this is a generic method, display its type arguments. // if (mi.IsGenericMethod) { Type[] typeArguments = mi.GetGenericArguments(); Console.WriteLine("\tList type arguments ({0}):", typeArguments.Length); foreach (Type tParam in typeArguments) { // IsGenericParameter is true only for generic type // parameters. // if (tParam.IsGenericParameter) { Console.WriteLine("\t\t{0} (unbound - parameter position {1})", tParam, tParam.GenericParameterPosition); } else { Console.WriteLine("\t\t{0}", tParam); } } } else { Console.WriteLine("\tThis is not a generic method."); } }