Jumat, 09 November 2007

How Does Reflection Detect This Paramater is Generic?

namespace PrintTypeParamsss
{
class Program
{
static void Main(string[] args)
{
PrintTypeparams(typeof(List<>));
PrintTypeparams(typeof(List));
PrintTypeparams(typeof(Dictionary));
PrintTypeparams(typeof(Dictionary));
PrintTypeparams(typeof(Nullable<>));

Console.ReadLine();
}
static void PrintTypeparams(Type t)
{
Console.WriteLine(t.FullName);
foreach (Type ty in t.GetGenericArguments())
{
Console.WriteLine("--> {0} {1} {2}",
ty.FullName,
ty.IsGenericParameter,
ty.IsGenericParameter ? ty.GenericParameterPosition : 0);
};

}
}
}

Tidak ada komentar: