Generic parameter information : Parameter « Reflection « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

public class MainClass
{
    public static void Main()
    {
        PrintTypeParams(typeof(List<>));
        PrintTypeParams(typeof(List<int>));
        PrintTypeParams(typeof(Nullable<>));
    }
    private static void PrintTypeParams(Type t)
    {
        Console.WriteLine(t.FullName);
        foreach (Type ty in t.GetGenericArguments())
        {
            Console.WriteLine(ty.FullName);
            Console.WriteLine(ty.IsGenericParameter);
            if (ty.IsGenericParameter)
            {
                Type[] constraints = ty.GetGenericParameterConstraints();
                foreach (Type c in constraints)
                    Console.WriteLine(c.FullName);
            }
        }
    }
}
System.Collections.Generic.List`1

True
System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicK
eyToken=b77a5c561934e089]]
System.Int32
False
System.Nullable`1

True
System.ValueType








19.6.Parameter
19.6.1.Invoke method with parameter type int
19.6.2.Generic parameter information
19.6.3.Analyze method parameters using reflection