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