C# 反射 获取类的所有属性


结论:反射 获取类的所有属性,默认情况,是不会遍历到静态成员的。

测试代码:

public class Class11
{
    public void test1()
    {
        c1 model = new c1();
        model.name = "name1";

        Type t = model.GetType();
        PropertyInfo[] pArray = t.GetProperties();
        Array.ForEach<PropertyInfo>(pArray, p =>
        {
            Console.WriteLine(p.Name);
        });
    }

    public class c1
    {
        public static string StrIds = "12333";//这个字段 反射时不会遍历到
        public string name { get; set; }
    }
}

输出的结果:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM