2
我必須從幾個將包含多個屬性的類創建pdf報告。 我需要在它前面顯示屬性值和標籤。如何使用c#屬性?
喜歡的東西:
detailsCalcul:
NÚMERO客戶端:valueOfMyProperty。
...
我的想法做這樣的:
[NomRapport("detailsCalcul")]
public class MyClass
{
[NomChamp("Numero client")]
public string NumeroClient { get; set; }
}
我成功地acessed我的兩個屬性的值:
System.Reflection.MemberInfo[] proprietes = typeof(MyClass).GetMembers();
MyClass client = new MyClass();
client.NumeroClient = "1234";
foreach (var p in proprietes)
{
var aa = p.GetCustomAttributes(true);
for (int i = 0; i < aa.Length; i++)
{
var test = aa[i];
if (test.GetType() == typeof(NomChampAttribute))
{
var nomChamp = ((NomChampAttribute)attributes[i]).ToString());
}
}
}
我想知道在我訪問屬性時是否可以訪問我的財產的價值?
感謝您的幫助,
紀堯姆
你必須通過變量p訪問屬性?您想做什麼?。此外,GetCustomAttributes有一個重載類型使用,你不需要過濾自己 –