本文共 1271 字,大约阅读时间需要 4 分钟。
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; } }}
转载地址:http://vtdaf.baihongyu.com/