MergablePropertyAttribute Classe

Definizione

Consente di specificare che questa proprietà può essere combinata con proprietà appartenenti ad altri oggetti in una finestra delle proprietà.

public ref class MergablePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class MergablePropertyAttribute : Attribute
public sealed class MergablePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type MergablePropertyAttribute = class
    inherit Attribute
type MergablePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class MergablePropertyAttribute
Inherits Attribute
Ereditarietà
MergablePropertyAttribute
Attributi

Esempio

L'esempio seguente contrassegna una proprietà come appropriato per l'unione.

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

Nell'esempio seguente viene illustrato come controllare il valore di MergablePropertyAttribute per MyProperty. Prima di tutto, il codice ottiene un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto . Successivamente, indicizza in PropertyDescriptorCollection per ottenere MyProperty. Restituisce quindi gli attributi per questa proprietà e li salva nella variabile degli attributi.

L'esempio presenta due modi diversi per controllare il valore di MergablePropertyAttribute. Nel secondo frammento di codice l'esempio chiama il Equals metodo con un static valore . Nell'ultimo frammento di codice l'esempio usa la AllowMerge proprietà per controllare il valore.

// 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

Se è stata contrassegnata una classe con MergablePropertyAttribute, usare il codice seguente per controllare il valore.

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

Commenti

Le proprietà contrassegnate con il MergablePropertyAttribute set su true possono essere combinate con proprietà appartenenti ad altri oggetti in un Finestra Proprietà. Le proprietà contrassegnate con il MergablePropertyAttribute set su false devono essere visualizzate separatamente. Il valore predefinito è true.

Nota

Quando si contrassegna una proprietà con l'oggetto MergablePropertyAttribute impostato su true, il valore di questo attributo viene impostato sul membro Yescostante . Per una proprietà contrassegnata con la MergablePropertyAttribute proprietà impostata su false, il valore è No. Pertanto, quando si vuole controllare il valore di questo attributo nel codice, è necessario specificare l'attributo come MergablePropertyAttribute.Yes o MergablePropertyAttribute.No.

Per altre informazioni, vedere Attributi.

Costruttori

MergablePropertyAttribute(Boolean)

Inizializza una nuova istanza della classe MergablePropertyAttribute.

Campi

Default

Specifica il valore predefinito, uguale a Yes, ovvero una proprietà può essere combinata con proprietà appartenenti ad altri oggetti in una finestra delle proprietà. Questo campo static è di sola lettura.

No

Consente di specificare che una proprietà non può essere combinata con proprietà appartenenti ad altri oggetti in una finestra delle proprietà. Questo campo static è di sola lettura.

Yes

Consente di specificare che una proprietà può essere combinata con proprietà appartenenti ad altri oggetti in una finestra delle proprietà. Questo campo static è di sola lettura.

Proprietà

AllowMerge

Ottiene un valore che indica se questa proprietà può essere combinata con proprietà appartenenti ad altri oggetti in una finestra delle proprietà.

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)

Metodi

Equals(Object)

Indica se questa istanza e un oggetto specificato sono uguali.

GetHashCode()

Restituisce il codice hash per l'istanza.

GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Determina se questo attributo è predefinito.

IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a

Vedi anche