C#反射中的一个核心类Type类

来源:互联网 发布:作图软件app文字 编辑:程序博客网 时间:2024/05/16 14:13

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

namespace _09反射中的一个核心类Type类
{
    class Program
    {
        static void Main(string[] args)
        {
            Person p = new Person();

            //1.获取Person类型的Type
            //1.通过对象调用GetType()方法
            Type type = p.GetType();
            //2.通过typeof关键字
            Type type1 = typeof(Person);
            //3.通过程序集对象的GetType()方法
            Assembly asm = Assembly.LoadFile(@"c:\testlib.dll");
            Type typs = asm.GetType("命名空间.类型名");
        }
    }

    public class Person
    {
        public string Name
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }
        public string Email
        {
            get;
            set;
        }

    }
}

原创粉丝点击