2009-07-14 91 views

回答

17

它取決於屬性。

應用於屬性類定義的屬性,帶有一個屬性[AttributeUsageAttribute.Inherited],用於確定屬性是否在派生類中繼承。

退房這個樣本

[global::System.AttributeUsage(AttributeTargets.Method, Inherited = true, 
    AllowMultiple = false)] 
public sealed class MyAttribute : Attribute 
{ 

    public MyAttribute (string FieldName) 
    { 
     //constructor. 
    } 

} 
+0

非常感謝您 – 2009-07-14 05:32:43

9

您可以指定通過應用AttributeUsage attribute到自定義的,並設置Inherited property(默認情況下爲真)。此屬性指示您的屬性是否可以由派生自應用了您的自定義屬性的類的派生類繼承。

[AttributeUsage(Inherited = false)] 
public class CustomAttribute : Attribute 
{ 
} 

推薦閱讀:

+2

+1真正的默認 – mrcrowl 2013-03-27 20:58:02