Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MergablePropertyAttribute Class

Specifies that this property can be combined with properties belonging to other objects in a Properties window.

For a list of all members of this type, see MergablePropertyAttribute Members.

System.Object
   System.Attribute
      System.ComponentModel.MergablePropertyAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.All)>
NotInheritable Public Class MergablePropertyAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.All)]
public sealed class MergablePropertyAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::All)]
public __gc __sealed class MergablePropertyAttribute : public
   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.All)
class MergablePropertyAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Properties that are marked with the MergablePropertyAttribute constructor of the value true can be combined with properties belonging to other objects in a Properties window. Properties that are marked with the MergablePropertyAttribute constructor of the value false must be displayed separately. The default is true.

Note   When you mark a property with the MergablePropertyAttribute constructor of the value true, the value of this attribute is set to the constant member Yes. For a property marked with the MergablePropertyAttribute constructor of the value false, the value is 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 Overview and Extending Metadata Using Attributes.

Example

The following example marks a property as appropriate to merge.

[Visual Basic] 
<MergableProperty(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

[C#] 
[MergableProperty(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }

[C++] 
public:
    [MergableProperty(true)]
    __property int get_MyProperty() {
        // Insert code here.
        return 0;
    }
    __property void set_MyProperty( int value ) {
        // Insert code here.
    }

[JScript] 
public MergableProperty(true)
function get MyProperty() : int{
  // Insert code here.
  return 0
}

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

The next example shows how to check the value of the MergablePropertyAttribute for MyProperty. First the code gets a PropertyDescriptorCollection with all the properties for the object. Next it indexes into the PropertyDescriptorCollection to get MyProperty. Then it returns the attributes for this property and saves them in the attributes variable.

The example presents two different ways of checking the value of the MergablePropertyAttribute. In the second code fragment, the example calls the Equals method with a static (Shared in Visual Basic) value. In the last code fragment, the example uses the AllowMerge property to check the value.

[Visual Basic] 
' 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 

[C#] 
// 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.
 }

[C++] 
// Gets the attributes for the property.
AttributeCollection* attributes = 
    TypeDescriptor::GetProperties(this)->Item[S"MyProperty"]->Attributes;

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

// This is another way to see if the property is bindable.
MergablePropertyAttribute* myAttribute = 
    dynamic_cast<MergablePropertyAttribute*>(attributes->Item[__typeof(MergablePropertyAttribute)]);
if(myAttribute->AllowMerge) {
    // Insert code here.
}

[JScript] 
// 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.
}

If you marked a class with the MergablePropertyAttribute, use the following code to check the value.

[Visual Basic] 
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If 

[C#] 
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
    // Insert code here.
 }

[C++] 
AttributeCollection* attributes = 
    TypeDescriptor::GetAttributes( __box(MyProperty));
if(attributes->Item[__typeof(MergablePropertyAttribute)]->Equals(MergablePropertyAttribute::Yes)) {
    // Insert code here.
}

[JScript] 
var attributes : AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
if(attributes(MergablePropertyAttribute).Equals(MergablePropertyAttribute.Yes)){
    // Insert code here.
}

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

MergablePropertyAttribute Members | System.ComponentModel Namespace | PropertyDescriptor | AttributeCollection | PropertyDescriptorCollection | Attribute

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft