Find Generic Methods
The metadata for each type in an assembly is represented by a NamedTypeDefinition
object. The object contains a collection of MethodDefinition objects that represent the metadata for each of the type’s methods. The
objects include an IsGeneric property that indicates whether the type or method is generic. Because FindGeneric works with an immutable representation of an assembly, the objects are represented by their
immutable interfaces, INamedTypeDefinition
The following example shows how FindGeneric searches an assembly for generic methods. The basic procedure can be easily adapted to search for other types of information.
foreach (INamedTypeDefinition type in assembly.GetAllTypes())
if (!type.IsGeneric) continue;
foreach (IMethodDefinition methodDefinition in type.Methods)
NameFormattingOptions.Signature | NameFormattingOptions.TypeParameters | NameFormattingOptions.TypeConstraints | NameFormattingOptions.ParameterName));
FindGeneric examines each type in the assembly. If the type is generic, FindGeneric examines the type’s MethodDefinition objects. For each generic method, FindGeneric uses the
method to print the signature in the command window.
Next: Add a Test Class to FindGeneric
Return to Beginning