Freigeben über


MergablePropertyAttribute-Klasse

Gibt an, dass diese Eigenschaft in einem Eigenschaftenfenster mit Eigenschaften von anderen Objekten kombiniert werden kann.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class MergablePropertyAttribute
    Inherits Attribute
'Usage
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

Hinweise

Eigenschaften, die mit MergablePropertyAttribute mit dem Wert true markiert sind, können in einem Eigenschaftenfenster mit Eigenschaften von anderen Objekten kombiniert werden. Eigenschaften, die mit MergablePropertyAttribute mit dem Wert false markiert sind, müssen getrennt angezeigt werden. Der Standardwert ist true.

Hinweis

Wenn Sie eine Eigenschaft mit MergablePropertyAttribute mit dem Wert true markieren, wird der Wert dieses Attributs auf den konstanten Member Yes festgelegt. Für eine mit MergablePropertyAttribute mit dem Wert false markierte Eigenschaft ist der Wert No. Wenn Sie den Wert dieses Attributs im Code überprüfen möchten, müssen Sie deshalb das Attribut als MergablePropertyAttribute.Yes oder MergablePropertyAttribute.No angeben.

Weitere Informationen finden Sie unter Übersicht über Attribute und Erweitern von Metadaten mithilfe von Attributen.

Beispiel

Im folgenden Beispiel wird eine Eigenschaft als zum Zusammenführen geeignet markiert.

<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.
}

Im folgenden Beispiel wird veranschaulicht, wie der Wert von MergablePropertyAttribute für MyProperty überprüft wird. Zunächst wird im Code eine PropertyDescriptorCollection mit allen Eigenschaften für das Objekt abgerufen. Anschließend wird MyProperty über den Index in PropertyDescriptorCollection abgerufen. Die Attribute für diese Eigenschaft werden zurückgegeben und in der Variablen attributes gespeichert.

Im Beispiel werden zwei verschiedene Möglichkeiten zum Überprüfen des Werts von MergablePropertyAttribute gezeigt. Im zweiten Codefragment wird im Beispiel die Equals-Methode mit einem static-Wert aufgerufen. Im letzten Codefragment wird der Wert anhand der AllowMerge-Eigenschaft überprüft.

' 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.
}

Verwenden Sie zur Prüfung folgenden Code, wenn Sie eine Klasse mit dem MergablePropertyAttribute markiert haben:

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.
}

Vererbungshierarchie

System.Object
   System.Attribute
    System.ComponentModel.MergablePropertyAttribute

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

MergablePropertyAttribute-Member
System.ComponentModel-Namespace
PropertyDescriptor
AttributeCollection-Klasse
PropertyDescriptorCollection
Attribute