我想提取屬性。屬性是自定義屬性。 但一些我怎麼不能使用object.id
的事情。
例如,我的評論代碼adpter.id
無效,即使您看到我已將該對象轉換爲其類型。無法提取屬性數據
下面是屬性代碼:
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public class Adapter : Attribute
{
// This class implements the Adapter Attribite
readonly int id;
readonly string Title;
public string Comment { get; set; }
private string[] Relation;
public Adapter(int id, string Title,string []relations)
{
this.id = id;
this.Title = Title;
this.Relation = relations;
}
}
除了下面的答案,您應該爲您的類型使用「-Attribute」後綴,派生自System.Attribute。例如。 「AdapterAttribute」。 – Dennis 2012-04-26 08:45:35