MergablePropertyAttribute 类

定义

指定该属性能与“属性”窗口中属于其他对象的属性组合。Specifies that this property can be combined with properties belonging to other objects in a Properties window.

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

示例

下面的示例将属性标记为适合 merge。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

下一个示例演示如何检查 MyPropertyMergablePropertyAttribute 的值。The 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 以获取 MyPropertyNext it indexes into the PropertyDescriptorCollection to get MyProperty. 然后,它将返回此属性的特性并将其保存在特性变量中。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. 在第二个代码片段中,此示例使用 static 值调用 Equals 方法。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的属性,该值是 No的。For a property marked with the MergablePropertyAttribute property set to false, the value is No. 因此,当你想要在代码中检查此属性的值时,必须将属性指定为 MergablePropertyAttribute.YesMergablePropertyAttribute.NoTherefore, 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)

将一组名称映射为对应的一组调度标识符。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)

适用于

另请参阅