DesignOnlyAttribute 類別

定義

指定屬性是否只能在設計階段進行設定。

public ref class DesignOnlyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class DesignOnlyAttribute : Attribute
public sealed class DesignOnlyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type DesignOnlyAttribute = class
    inherit Attribute
type DesignOnlyAttribute = class
    inherit Attribute
Public NotInheritable Class DesignOnlyAttribute
Inherits Attribute
繼承
DesignOnlyAttribute
屬性

範例

下列範例會 GetLanguage 建立 屬性。 屬性會以 DesignOnlyAttribute 標示。

public:
   [DesignOnly(true)]
   property CultureInfo^ GetLanguage 
   {
      CultureInfo^ get()
      {
         // Insert code here.
         return myCultureInfo;
      }
      void set( CultureInfo^ value )
      {
         // Insert code here.
      }
   }
[DesignOnly(true)]
 public CultureInfo GetLanguage {
    get {
       // Insert code here.
       return myCultureInfo;
    }
    set {
       // Insert code here.
    }
 }
<DesignOnly(True)> _
Public Property GetLanguage() As CultureInfo
    Get
        ' Insert code here.
        Return myCultureInfo
    End Get
    Set
        ' Insert code here.
    End Set
End Property

下一個範例會取得 的值 DesignOnlyAttribute 。 首先,程式碼會取得 PropertyDescriptorCollection 具有 物件之所有屬性的 。 接下來,它會編制索引至 PropertyDescriptorCollection 以尋找 GetLanguage 屬性。 然後它會傳回此屬性的屬性,並將其儲存在屬性變數中。

然後,此範例會列印屬性的設計方式是只從 AttributeCollection 擷取 DesignOnlyAttribute ,並將它寫入主控台畫面。

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "GetLanguage" ]->Attributes;

/* Prints whether the property is marked as DesignOnly 
by retrieving the DesignOnlyAttribute from the AttributeCollection. */
DesignOnlyAttribute^ myAttribute = dynamic_cast<DesignOnlyAttribute^>(attributes[ DesignOnlyAttribute::typeid ]);
Console::WriteLine( "This property is design only :{0}", myAttribute->IsDesignOnly );
// Gets the attributes for the property.
 AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes;

 /* Prints whether the property is marked as DesignOnly 
  * by retrieving the DesignOnlyAttribute from the AttributeCollection. */
 DesignOnlyAttribute myAttribute = 
    (DesignOnlyAttribute)attributes[typeof(DesignOnlyAttribute)];
 Console.WriteLine("This property is design only :" +
    myAttribute.IsDesignOnly.ToString());
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes

' Prints whether the property is marked as DesignOnly 
' by retrieving the DesignOnlyAttribute from the AttributeCollection.
Dim myAttribute As DesignOnlyAttribute = _
    CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute)
Console.WriteLine(("This property is design only :" & _
    myAttribute.IsDesignOnly.ToString()))

備註

標示為 的 DesignOnlyAttribute 成員 true 只能在設計階段設定。 這些屬性通常只存在於設計階段,而且不會對應至執行時間物件上的實際屬性。

沒有屬性或標示 DesignOnlyAttribute 為 的成員,可以在執行時間期間設定 。 false 預設為 false

屬性, DesignOnlyAttribute 其 值已 true 序列化為 .resx 檔案,而不是 InitializeComponent 方法。

如需詳細資訊,請參閱屬性

建構函式

DesignOnlyAttribute(Boolean)

初始化 DesignOnlyAttribute 類別的新執行個體。

欄位

Default

指定 DesignOnlyAttribute 的預設值,就是 No。 這個 static 欄位是唯讀的。

No

指定屬性可在設計階段或 Run Time 進行設定。 這個 static 欄位是唯讀的。

Yes

指定屬性只能在設計階段進行設定。 這個 static 欄位是唯讀的。

屬性

IsDesignOnly

取得值,表示屬性是否只能在設計階段進行設定。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 DesignOnlyAttribute

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。

IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱