MergablePropertyAttribute 類別

定義

指定這個屬性可以在 [屬性] 視窗中結合其他物件的屬性。Specifies that this property can be combined with properties belonging to other objects in a Properties window.

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

範例

下列範例會將屬性標示為適用以進行合併。The following example marks a property as appropriate to merge.

public:
   [MergableProperty(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
[MergableProperty(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }
<MergableProperty(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

下一個範例顯示如何檢查的值MergablePropertyAttributeMyPropertyThe next example shows how to check the value of the MergablePropertyAttribute for MyProperty. 首先, 程式碼會PropertyDescriptorCollection取得具有物件之所有屬性的。First the code gets a PropertyDescriptorCollection with all the properties for the object. 接著, 它會將PropertyDescriptorCollection索引至MyProperty以取得。Next it indexes into the PropertyDescriptorCollection to get MyProperty. 然後, 它會傳回這個屬性的屬性, 並將其儲存在 attributes 變數中。Then it returns the attributes for this property and saves them in the attributes variable.

此範例會提供兩種不同的方式來檢查的MergablePropertyAttribute值。The example presents two different ways of checking the value of the MergablePropertyAttribute. 在第二個程式碼片段中, 此範例Equalsstatic使用值來呼叫方法。In the second code fragment, the example calls the Equals method with a static value. 在最後一個程式碼片段中, 此範例會AllowMerge使用屬性來檢查值。In the last code fragment, the example uses the AllowMerge property to check the value.

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

// Checks to see if the value of the MergablePropertyAttribute is Yes.
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
   // Insert code here.
}

// This is another way to see if the property is bindable.
MergablePropertyAttribute^ myAttribute = dynamic_cast<MergablePropertyAttribute^>(attributes[ MergablePropertyAttribute::typeid ]);
if ( myAttribute->AllowMerge )
{
   // Insert code here.
}
// Gets the attributes for the property.
 AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
 
 // Checks to see if the value of the MergablePropertyAttribute is Yes.
 if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
    // Insert code here.
 }
 
 // This is another way to see if the property is bindable.
 MergablePropertyAttribute myAttribute = 
    (MergablePropertyAttribute)attributes[typeof(MergablePropertyAttribute)];
 if(myAttribute.AllowMerge) {
    // Insert code here.
 }
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Checks to see if the value of the MergablePropertyAttribute is Yes.
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If 

' This is another way to see if the property is bindable.
Dim myAttribute As MergablePropertyAttribute = _
    CType(attributes(GetType(MergablePropertyAttribute)), MergablePropertyAttribute)
If myAttribute.AllowMerge Then
    ' Insert code here.
End If 

如果您已使用標記類別MergablePropertyAttribute, 請使用下列程式碼來檢查值。If you marked a class with the MergablePropertyAttribute, use the following code to check the value.

AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
    // Insert code here.
 }
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If 

備註

MergablePropertyAttribute設定為true的屬性, 可以結合屬於屬性視窗中其他物件的屬性。Properties that are marked with the MergablePropertyAttribute set to true can be combined with properties belonging to other objects in a Properties window. 以設定為MergablePropertyAttribute false的標記屬性必須分別顯示。Properties that are marked with the MergablePropertyAttribute set to false must be displayed separately. 預設為 trueThe default is true.

注意

當您將設定為的MergablePropertyAttribute屬性標記為true時, 這個屬性的值會設定為常數成員。 YesWhen you mark a property with the MergablePropertyAttribute set to true, the value of this attribute is set to the constant member Yes. 對於將屬性設定為MergablePropertyAttribute false的屬性 (property), 此值No為。For a property marked with the MergablePropertyAttribute property set to false, the value is No. 因此, 當您想要在程式碼中檢查這個屬性的值時, 您必須將屬性指定MergablePropertyAttribute.YesMergablePropertyAttribute.No或。Therefore, when you want to check the value of this attribute in your code, you must specify the attribute as MergablePropertyAttribute.Yes or MergablePropertyAttribute.No.

如需詳細資訊,請參閱屬性For more information, see Attributes.

建構函式

MergablePropertyAttribute(Boolean)

初始化 MergablePropertyAttribute 類別的新執行個體。Initializes a new instance of the MergablePropertyAttribute class.

欄位

Default

指定預設值,即 Yes,此屬性可與隸屬於 [屬性] 視窗中其他物件的屬性合併。Specifies the default value, which is Yes, that is a property can be combined with properties belonging to other objects in a Properties window. 這個 static 欄位是唯讀的。This static field is read-only.

No

指定屬性不可以在 [屬性] 視窗中結合其他物件的屬性。Specifies that a property cannot be combined with properties belonging to other objects in a Properties window. 這個 static 欄位是唯讀的。This static field is read-only.

Yes

指定屬性可以在 [屬性] 視窗中結合其他物件的屬性。Specifies that a property can be combined with properties belonging to other objects in a Properties window. 這個 static 欄位是唯讀的。This static field is read-only.

屬性

AllowMerge

取得值,表示這個屬性是否可在 [屬性] 視窗中結合其他物件的屬性。Gets a value indicating whether this property can be combined with properties belonging to other objects in a Properties window.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

指示這個執行個體和指定的物件是否相等。Indicates whether this instance and a specified object are equal.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。Determines if this attribute is the default.

Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

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

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於

另請參閱