Type.GetGenericArguments() : Type « System « C# / C Sharp by API






Type.GetGenericArguments()

   

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

   
    
    
  








Related examples in the same category

1.Type.BaseType
2.Type.ContainsGenericParameters
3.Type.FullName
4.Type.GetConstructor
5.Type.GetCustomAttributes
6.Type.GetEvents()
7.Type.GetFields()
8.Type.GetGenericTypeDefinition()
9.Type.GetInterfaces()
10.Type.GetMethod(String methodName);
11.Type.GetMethods()
12.Type.GetProperties()
13.Type.GetType(String typeName)
14.Type.GetType(String typeName, true)
15.Type.GetType(String typeName, true, true);
16.Type.IsAbstract
17.Type.IsClass
18.Type.IsCOMObject
19.Type.IsEnum
20.Type.IsGenericTypeDefinition
21.Type.IsSealed
22.Type.MakeGenericType
23.Type.Name
24.Type.ReflectionOnlyGetType
25.Type.UnderlyingSystemType