Sdílet prostřednictvím


MergablePropertyAttribute Třída

Definice

Určuje, že tuto vlastnost lze kombinovat s vlastnostmi patřícími do jiných objektů v okně Vlastnosti.

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
Dědičnost
MergablePropertyAttribute
Atributy

Příklady

Následující příklad označuje vlastnost, která se má sloučit.

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

Další příklad ukazuje, jak zkontrolovat hodnotu MergablePropertyAttribute pro MyProperty. Nejprve kód získá PropertyDescriptorCollection všechny vlastnosti objektu. Dále indexuje do získání PropertyDescriptorCollectionMyProperty. Pak vrátí atributy pro tuto vlastnost a uloží je do proměnné atributů.

Příklad představuje dva různé způsoby kontroly hodnoty MergablePropertyAttribute. Ve druhém fragmentu kódu volá příklad metodu Equalsstatic s hodnotou. V posledním fragmentu kódu příklad používá AllowMerge vlastnost ke kontrole hodnoty.

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

Pokud jste označili třídu pomocí MergablePropertyAttributepříkazu , pomocí následujícího kódu zkontrolujte hodnotu.

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

Poznámky

Vlastnosti označené nastavenou MergablePropertyAttribute sadou true lze kombinovat s vlastnostmi patřícími do jiných objektů v okně Vlastnosti. Vlastnosti označené nastavenou MergablePropertyAttribute sadou false musí být zobrazeny samostatně. Výchozí hodnota je true.

Poznámka:

Když označíte vlastnost nastavenou MergablePropertyAttribute na truehodnotu , hodnota tohoto atributu je nastavena na konstantní člen Yes. Pro vlastnost označenou vlastností nastavenou MergablePropertyAttribute na falsehodnotu je Nohodnota . Proto pokud chcete zkontrolovat hodnotu tohoto atributu v kódu, musíte zadat atribut jako MergablePropertyAttribute.Yes nebo MergablePropertyAttribute.No.

Další informace naleznete v tématu Atributy.

Konstruktory

Name Description
MergablePropertyAttribute(Boolean)

Inicializuje novou instanci MergablePropertyAttribute třídy.

Pole

Name Description
Default

Určuje výchozí hodnotu, což je , to je Yesvlastnost lze kombinovat s vlastnostmi patřícími do jiných objektů v okně Vlastnosti. Toto static pole je jen pro čtení.

No

Určuje, že vlastnost nelze kombinovat s vlastnostmi patřícími do jiných objektů v okně Vlastnosti. Toto static pole je jen pro čtení.

Yes

Určuje, že vlastnost lze kombinovat s vlastnostmi patřícími do jiných objektů v okně Vlastnosti. Toto static pole je jen pro čtení.

Vlastnosti

Name Description
AllowMerge

Získá hodnotu určující, zda tato vlastnost lze kombinovat s vlastnostmi patřícími do jiných objektů v okně Vlastnosti.

TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tento Attribute.

(Zděděno od Attribute)

Metody

Name Description
Equals(Object)

Určuje, zda tato instance a zadaný objekt jsou rovny.

GetHashCode()

Vrátí kód hash pro tuto instanci.

GetType()

Získá Type aktuální instance.

(Zděděno od Object)
IsDefaultAttribute()

Určuje, zda je tento atribut výchozí.

Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která určuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu pro rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také