C#VS 2005:如何在运行时获取类的公共成员列表?

sim*_*mon 2 c# reflection typeof

我正在尝试在运行时获取类memeber变量列表.我知道这可能是使用typeof和反射.但找不到一个例子.请有人为我照亮.

这是伪代码示例:

Class Test01
{ 
 public string str01;
 public string str02;
 public int myint01;
}
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西(伪代码):

Test01 tt = new Test01();
foreach(variable v in tt.PublicVariableList)
{
   debug.print v.name;
   debug.print v.type;
}
Run Code Online (Sandbox Code Playgroud)

请帮我弄清楚如何在C#VS2005中做到这一点

非常感谢

Jon*_*eet 9

如果您在公共领域之后使用tt.GetType().GetFields()

如果您需要其他成员,请对特定成员使用GetProperties(),GetMethods(),GetEvents()等,或者使用GetMembers()来获取所有成员.

如果要访问非公共成员,或者将搜索限制为静态成员(或仅限于实例成员),则每个方法都有一个重载接受BindingFlags.