Generic parameter information : Parameter : Reflection C# Examples


C# Examples » Reflection » Parameter »

 

Generic parameter information









    
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);
                        }
                }
        }
}
    
   
  
   



Output

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


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Reflection
» Parameter