MergablePropertyAttribute 类

指定该属性能与“属性”窗口中属于其他对象的属性 (Property) 组合。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class MergablePropertyAttribute
    Inherits Attribute
用法
Dim instance As MergablePropertyAttribute
[AttributeUsageAttribute(AttributeTargets.All)] 
public sealed class MergablePropertyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All)] 
public ref class MergablePropertyAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ 
public final class MergablePropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All) 
public final class MergablePropertyAttribute extends Attribute

备注

通过将 MergablePropertyAttribute 设置为 true 进行标记的属性 (Property) 可以与“属性”窗口中属于其他对象的属性 (Property) 组合。通过将 MergablePropertyAttribute 设置为 false 进行标记的属性 (Property) 必须单独显示。默认为 true

提示

当使用设置为 trueMergablePropertyAttribute 标记某个属性 (Property) 时,此属性 (Attribute) 的值会被设置为常数成员 Yes。对于通过将 MergablePropertyAttribute 属性 (Property) 设置为 false 进行标记的属性 (Property),此值为 No。因此,若要检查代码中此属性 (Attribute) 的值,必须将该属性 (Attribute) 指定为 MergablePropertyAttribute.YesMergablePropertyAttribute.No

有关更多信息,请参见 属性 (Attribute) 概述利用属性扩展元数据

示例

下面的示例将属性标记为适合合并。

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

/** @property
 */
public int get_MyProperty()
{
    // Insert code here.
    return 0;
} //get_MyProperty

/** @property
 */
public void set_MyProperty(int value)
{
    // Insert code here.
} //set_MyProperty 
public MergableProperty(true)
function get MyProperty() : int{
  // Insert code here.
  return 0
}

function set MyProperty(value : int){
  // Insert code here.
}

下一个示例演示如何检查 MyPropertyMergablePropertyAttribute 的值。首先,代码获取具有该对象的所有属性 (Property) 的 PropertyDescriptorCollection。接下来,对 PropertyDescriptorCollection 进行索引,以获取 MyProperty。然后它返回该属性 (Property) 的属性 (Attribute),并将它们保存到属性 (Attribute) 变量中。

该示例提供了两种不同的方法来检查 MergablePropertyAttribute 的值。在第二个代码段中,该示例使用一个 static 值调用 Equals 方法。在最后一个代码段中,该示例使用 AllowMerge 属性 (Property) 检查该值。

' 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 
// 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.
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).get_Item(
    "MyProperty").get_Attributes();

// Checks to see if the value of the MergablePropertyAttribute is Yes.
if (attributes.get_Item(
        MergablePropertyAttribute.class.ToType()).Equals
        (MergablePropertyAttribute.Yes)) {

    // Insert code here.
}

// This is another way to see if the property is bindable.
MergablePropertyAttribute myAttribute = ((MergablePropertyAttribute)
    (attributes.get_Item(MergablePropertyAttribute.class.ToType())));
if (myAttribute.get_AllowMerge()) {
    // Insert code here.
}
// Gets the attributes for the property.
var attributes : AttributeCollection = TypeDescriptor.GetProperties(this)["MyProperty"].Attributes

// Checks to see if the value of the MergablePropertyAttribute is Yes.
if(attributes(MergablePropertyAttribute).Equals(MergablePropertyAttribute.Yes)){
  // Insert code here.
}

// This is another way to see if the property is bindable.
var myAttribute : MergablePropertyAttribute = MergablePropertyAttribute(attributes(MergablePropertyAttribute))
if(myAttribute.AllowMerge){
  // Insert code here.
}

如果将类标记为 MergablePropertyAttribute,请使用下列代码检查该值。

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

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.MergablePropertyAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

MergablePropertyAttribute 成员
System.ComponentModel 命名空间
PropertyDescriptor
AttributeCollection 类
PropertyDescriptorCollection
Attribute