日期:2014-05-18  浏览次数:20783 次

请教如何遍历对象属性
如题 有没有什么方法可以做到呢?

------解决方案--------------------
参考如下代码:
C# code
using System.Reflection;

Type vType = GetType();
if (vType != null)
{
    MethodInfo[] vMethodInfos = vType.GetMethods();
    foreach (MethodInfo vMethodInfo in vMethodInfos)
        textBox1.AppendText(vMethodInfo.Name + "\r\n");

    FieldInfo[] vFieldInfos = vType.GetFields();
    foreach (FieldInfo vFieldInfo in vFieldInfos)
        textBox1.AppendText(vFieldInfo.Name + "\r\n");

    PropertyInfo[] vPropertyInfos = vType.GetProperties();
    foreach (PropertyInfo vPropertyInfo in vPropertyInfos)
        textBox1.AppendText(vPropertyInfo.Name + "\r\n");
}