MergablePropertyAttribute 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定该属性能与“属性”窗口中属于其他对象的属性组合。
public ref class MergablePropertyAttribute sealed : Attribute[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class MergablePropertyAttribute : Attributepublic sealed class MergablePropertyAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.All)>]
type MergablePropertyAttribute = class
    inherit Attributetype MergablePropertyAttribute = class
    inherit AttributePublic NotInheritable Class MergablePropertyAttribute
Inherits Attribute- 继承
- 属性
示例
以下示例将属性标记为适合合并。
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
下一个示例演示如何为 检查 的值MergablePropertyAttributeMyProperty。 首先,代码获取具有 PropertyDescriptorCollection 对象的所有属性的 。 接下来,它会索引到 中 PropertyDescriptorCollection 以获取 MyProperty。 然后,它将返回此属性的属性,并将其保存在 attributes 变量中。
该示例演示了检查 的值的 MergablePropertyAttribute两种不同方法。 第二个代码片段中,该示例使用 值static调用 Equals 方法。 在最后一个代码片段中,该示例使用 AllowMerge 属性检查值。
// 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请使用以下代码检查值。
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
注解
将 MergablePropertyAttributetrue 设置为 标记的属性可以与属于属性窗口中其他对象的属性组合使用。 标记为 MergablePropertyAttribute 设置为 false 的属性必须单独显示。 默认为 true。
注意
将 属性MergablePropertyAttributetrue标记为 时,此属性的值设置为常量成员 Yes。 对于标记为 的 MergablePropertyAttribute 属性设置为 false的属性,值为 No。 因此,如果要在代码中检查此属性的值,必须将 特性指定为 MergablePropertyAttribute.Yes 或 MergablePropertyAttribute.No。
有关更多信息,请参阅特性。
构造函数
| MergablePropertyAttribute(Boolean) | 初始化 MergablePropertyAttribute 类的新实例。 | 
字段
| Default | 指定默认值 Yes,它可以与“属性”窗口中属于其他对象的属性组合。 此  | 
| No | 指定属性不能与“属性”窗口中属于其他对象的属性组合。 此  | 
| Yes | 指定属性能与“属性”窗口中属于其他对象的属性组合。 此  | 
属性
| AllowMerge | 获取一个值,该值指示该属性能否与“属性”窗口属于其他对象的属性组合。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
方法
| Equals(Object) | 指示此实例与指定对象是否相等。 | 
| GetHashCode() | 返回此实例的哈希代码。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 确定此特性是否为默认特性。 | 
| IsDefaultAttribute() | 在派生类中重写时,指示此实例的值是否是派生类的默认值。(继承自 Attribute) | 
| Match(Object) | 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。(继承自 Attribute) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |