Comparteix a través de


MergablePropertyAttribute Clase

Definición

Especifica que esta propiedad se puede combinar con propiedades que pertenecen a otros objetos de una ventana Propiedades.

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
Herencia
MergablePropertyAttribute
Atributos

Ejemplos

En el ejemplo siguiente se marca una propiedad según corresponda para combinar.

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

En el ejemplo siguiente se muestra cómo comprobar el valor de MergablePropertyAttribute para MyProperty. En primer lugar, el código obtiene un PropertyDescriptorCollection objeto con todas las propiedades del objeto . A continuación, se indexa en para PropertyDescriptorCollection obtener MyProperty. A continuación, devuelve los atributos de esta propiedad y los guarda en la variable attributes.

En el ejemplo se presentan dos formas diferentes de comprobar el valor de MergablePropertyAttribute. En el segundo fragmento de código, el ejemplo llama al Equals método con un static valor . En el último fragmento de código, en el ejemplo se usa la AllowMerge propiedad para comprobar el 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

Si marcó una clase con MergablePropertyAttribute, use el código siguiente para comprobar el 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

Comentarios

Las propiedades marcadas con el MergablePropertyAttribute conjunto true en se pueden combinar con propiedades que pertenecen a otros objetos en una ventana Propiedades. Las propiedades marcadas con el MergablePropertyAttribute conjunto false en deben mostrarse por separado. El valor predeterminado es true.

Nota:

Cuando se marca una propiedad con el MergablePropertyAttribute establecido trueen , el valor de este atributo se establece en el miembro Yesconstante . Para una propiedad marcada con la MergablePropertyAttribute propiedad establecida falseen , el valor es No. Por lo tanto, cuando desee comprobar el valor de este atributo en el código, debe especificar el atributo como MergablePropertyAttribute.Yes o MergablePropertyAttribute.No.

Para obtener más información, consulte Attributes (Atributos).

Constructores

Nombre Description
MergablePropertyAttribute(Boolean)

Inicializa una nueva instancia de la clase MergablePropertyAttribute.

Campos

Nombre Description
Default

Especifica el valor predeterminado, que es Yes, que es una propiedad se puede combinar con propiedades que pertenecen a otros objetos de una ventana Propiedades. Este static campo es de solo lectura.

No

Especifica que una propiedad no se puede combinar con propiedades que pertenecen a otros objetos de una ventana Propiedades. Este static campo es de solo lectura.

Yes

Especifica que una propiedad se puede combinar con propiedades que pertenecen a otros objetos de una ventana Propiedades. Este static campo es de solo lectura.

Propiedades

Nombre Description
AllowMerge

Obtiene un valor que indica si esta propiedad se puede combinar con propiedades que pertenecen a otros objetos de una ventana Propiedades.

TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.

(Heredado de Attribute)

Métodos

Nombre Description
Equals(Object)

Indica si esta instancia y un objeto especificado son iguales.

GetHashCode()

Devuelve el código hash de esta instancia.

GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
IsDefaultAttribute()

Determina si este atributo es el valor predeterminado.

Match(Object)

Cuando se reemplaza en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.

(Heredado de Attribute)
MemberwiseClone()

Crea una copia superficial del Objectactual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Implementaciones de interfaz explícitas

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

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.

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

Recupera la información de tipo de un objeto, que se puede usar para obtener la información de tipo de una interfaz.

(Heredado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).

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

Proporciona acceso a propiedades y métodos expuestos por un objeto .

(Heredado de Attribute)

Se aplica a

Consulte también