Compartilhar via


MergablePropertyAttribute Classe

Definição

Especifica que essa propriedade pode ser combinada com propriedades pertencentes a outros objetos em uma janela Propriedades.

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
Herança
MergablePropertyAttribute
Atributos

Exemplos

O exemplo a seguir marca uma propriedade conforme apropriado para mesclagem.

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

O exemplo a seguir mostra como verificar o valor do MergablePropertyAttribute .MyProperty Primeiro, o código obtém uma PropertyDescriptorCollection com todas as propriedades do objeto. Em seguida, ele indexa para obter PropertyDescriptorCollectionMyProperty. Em seguida, retorna os atributos dessa propriedade e os salva na variável de atributos.

O exemplo apresenta duas maneiras diferentes de verificar o valor do MergablePropertyAttribute. No segundo fragmento de código, o exemplo chama o Equals método com um static valor. No último fragmento de código, o exemplo usa a AllowMerge propriedade para verificar o valor.

// 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 você marcou uma classe com a MergablePropertyAttribute, use o código a seguir para verificar o valor.

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

Comentários

As propriedades marcadas com o MergablePropertyAttribute conjunto a true serem combinadas com propriedades pertencentes a outros objetos em uma janela Propriedades. As propriedades marcadas com o MergablePropertyAttribute conjunto a false serem exibidas separadamente. O padrão é true.

Observação

Quando você marca uma propriedade com o MergablePropertyAttribute conjunto como true, o valor desse atributo é definido como o membro Yesconstante. Para uma propriedade marcada com a MergablePropertyAttribute propriedade definida como false, o valor é No. Portanto, quando você deseja verificar o valor desse atributo em seu código, você deve especificar o atributo como MergablePropertyAttribute.Yes ou MergablePropertyAttribute.No.

Para obter mais informações, consulte Atributos.

Construtores

Nome Description
MergablePropertyAttribute(Boolean)

Inicializa uma nova instância da classe MergablePropertyAttribute.

Campos

Nome Description
Default

Especifica o valor padrão, ou seja Yes, uma propriedade pode ser combinada com propriedades pertencentes a outros objetos em uma janela Propriedades. Este static campo é somente leitura.

No

Especifica que uma propriedade não pode ser combinada com propriedades pertencentes a outros objetos em uma janela Propriedades. Este static campo é somente leitura.

Yes

Especifica que uma propriedade pode ser combinada com propriedades pertencentes a outros objetos em uma janela Propriedades. Este static campo é somente leitura.

Propriedades

Nome Description
AllowMerge

Obtém um valor que indica se essa propriedade pode ser combinada com propriedades pertencentes a outros objetos em uma janela Propriedades.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para esse Attribute.

(Herdado de Attribute)

Métodos

Nome Description
Equals(Object)

Indica se essa instância e um objeto especificado são iguais.

GetHashCode()

Retorna o código hash dessa instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se esse atributo é o padrão.

Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo de um objeto, que podem ser usadas para obter as informações de tipo de uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Confira também