反射获取类的公有变量
using System.Reflection;
ReflectClass r = new ReflectClass();
Type type = r.GetType();

//获取公有成员
FieldInfo[] fieldInfo = type.GetFields();
foreach (FieldInfo f in fieldInfo) {
    Console.Write(f.Name + " ");
}

FieldInfo还有PropertyInfo和MethodInfo等类都是在System.Reflection下的

Type类的GetFields方法能过获取到类的所有公有成员变量的信息


首页 我的博客
粤ICP备17103704号