Generic Type Reflection : Introduction « Generic « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;

    class GenericTypeReflection
    {
        static void Main()
        {
            string listTypeName = "System.Collections.Generic.List";

            Type defByName = Type.GetType(listTypeName);

            Type closedByName = Type.GetType(listTypeName + "[System.String]");
            Type closedByMethod = defByName.MakeGenericType(typeof(string));
            Type closedByTypeof = typeof(List<string>);

            Console.WriteLine(closedByMethod == closedByName);
            Console.WriteLine(closedByName == closedByTypeof);

            Type defByTypeof = typeof(List<>);
            Type defByMethod = closedByName.GetGenericTypeDefinition();

            Console.WriteLine(defByMethod == defByName);
            Console.WriteLine(defByName == defByTypeof);
        }
    }








18.1.Introduction
18.1.1.Life without generics
18.1.2.Generic Type Reflection