C# 反射

来源:互联网 发布:意大利火车时刻表软件 编辑:程序博客网 时间:2024/05/29 02:45
using System;using System.Reflection;namespace ConsoleApplication20{    class Program    {        static void Main(string[] args)        {            /*            string n = "grayworm";            Type t = n.GetType();            foreach (MemberInfo mi in t.GetMembers())            {                Console.WriteLine("{0}/t{1}", mi.MemberType, mi.Name);            }            */            AA aa = new AA(1,2);            Type t = aa.GetType();            foreach (MemberInfo mi in t.GetMembers())            {                Console.WriteLine("{0}/{1}", mi.MemberType, mi.Name);            }            ConstructorInfo[] ci = t.GetConstructors();    //获取类的所有构造函数            foreach (ConstructorInfo c in ci) //遍历每一个构造函数            {                ParameterInfo[] ps = c.GetParameters();    //取出每个构造函数的所有参数                foreach (ParameterInfo pi in ps)   //遍历并打印所该构造函数的所有参数                {                    Console.Write(pi.ParameterType.ToString() + " " + pi.Name + ",");                }                Console.WriteLine();            }        }    }    class AA    {        public int a { get; set; }        public AA(int a,int b)        {            this.a = a + b;        }        public static int A(int x)        {            return x + 1;        }    }}

0 0
原创粉丝点击