Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Reflection;
Namespace GenericReflectingApp1
{
Class Program
{
Static void Main (string [] args)
{
MyGeneric <string> myString = new myGeneric <string> ();
MyString. Show <int> (100 );
ShowTypeInfo (myString. GetType ());
// An error occurs. "An ambiguous match is found. ",
// MethodInfo myMethod = myString. GetType (). GetMethod ("Show ");
// How to specify generic method parameters
// MethodInfo myMethod = myString. GetType (). GetMethod ("Show", new Type [] {});
// Console. WriteLine (string. Format ("Is Generic Method: {0}", myMethod. IsGenericMethod. ToString ()));
Console. Read ();
}
Static void ShowTypeInfo (Type t)
{
Console. WriteLine (string. Format ("TypeName: {0} Method List:", t. Name ));
Foreach (MethodInfo obj in t. GetMethods ())
{
Console. WriteLine (string. Format ("Method Name: {0}; IsGeneric Method: {1}; ContainsGenericParameters: {2 }",
Obj. Name, obj. IsGenericMethod. ToString (), obj. ContainsGenericParameters. ToString ()));
If (obj. GetGenericArguments (). Count ()> 0)
{
Console. WriteLine (string. Format ("Generic Arguments s count: {0}", obj. GetGenericArguments () [0]. Name
));
}
}
}
& Nbs