Generic methods are defined in the .NET documentation as methods that are declared with type parameters (e.g., Swap<T>( T x, T y ) ). Here, methods that access class-level type parameters are also considered to be generic methods. For instance, the DoSomething method below is considered a generic method.
class GenericClass<T>
{
void DoSomething( T value );
}
When a generic method is presented in a call stack or in the method view of the Call Stacks/Methods page, the type parameters of the method or the class containing the method are presented. However, due to the way the runtime optimizes the generation of generic methods, the profiler cannot always retrieve the actual type parameters of the method.
When a generic method is instantiated with a reference type, the runtime allows this instantiation to be shared for all reference types. For example, the methods List<string>.Add() and List<Control>.Add(), both use the same instantiation of Add,since System.String and System.Windows.Form.Control are both reference types.
This sharing of instantiations prevents the profiler from identifying the actual instantiation of a method. Instead, the profiler will present the methods with the generic type parameter names used when designing the class. Thus, both of the Add methods will be named List<T>.Add().
If a generic method is instantiated only using value type parameters, then no sharing of method code occurs, and the profiler can correctly identify the instantiated method. For instance, the methods List<int>.Add() and List<float>.Add() will be presented with the actual type parameters.
The same rules apply to generic methods that are declared with type parameters. For instance, Swap<string>() and Swap<Control>() will be presented as Swap<T>(), but Swap<int>() will be presented as Swap<int>().