代码清单3-12 获取泛型和已构造Type对象的各种方式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string listTypeName = "System.Collections.Generic.List`1";
            Type defByName = Type.GetType(listTypeName);
            Type closedByName = Type.GetType(listTypeName + "[System.String]");
            Type closedByMethod = defByName.MakeGenericType(typeof(string));
            Type closeByTypeof = typeof(List<string>);
            Type defByTypeof = typeof(List<>);
            Type defByMethod = closedByName.GetGenericTypeDefinition();
            Console.WriteLine(closeByTypeof);
            Console.ReadKey();
        }
    }
}

 

posted on 2017-06-07 15:29  liuslayer  阅读(245)  评论(0编辑  收藏  举报

导航