MergablePropertyAttribute Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger att den här egenskapen kan kombineras med egenskaper som tillhör andra objekt i en Properties window.
public ref class MergablePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class MergablePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type MergablePropertyAttribute = class
inherit Attribute
Public NotInheritable Class MergablePropertyAttribute
Inherits Attribute
- Arv
- Attribut
Exempel
I följande exempel markeras en egenskap som lämplig för sammanslagning.
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
I nästa exempel visas hur du kontrollerar värdet för MergablePropertyAttribute för MyProperty. Först hämtar koden en PropertyDescriptorCollection med alla egenskaper för objektet. Därefter indexerar den till PropertyDescriptorCollection för att hämta MyProperty. Sedan returneras attributen för den här egenskapen och sparas i attributvariabeln.
I exemplet visas två olika sätt att kontrollera värdet för MergablePropertyAttribute. I det andra kodfragmentet anropar Equals exemplet metoden med ett static värde. I det sista kodfragmentet använder AllowMerge exemplet egenskapen för att kontrollera värdet.
// 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
Om du har markerat en klass med MergablePropertyAttributeanvänder du följande kod för att kontrollera värdet.
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
Kommentarer
Egenskaper som är markerade med MergablePropertyAttribute inställda på true kan kombineras med egenskaper som tillhör andra objekt i en Properties window. Egenskaper som är markerade med uppsättningen MergablePropertyAttribute måste false visas separat. Standardvärdet är true.
Note
När du markerar en egenskap med MergablePropertyAttribute värdet inställd truepå anges värdet för det här attributet till den konstanta medlemmen Yes. För en egenskap som är markerad med egenskapen MergablePropertyAttribute inställd på falseär Novärdet . När du vill kontrollera värdet för det här attributet i koden måste du därför ange attributet som MergablePropertyAttribute.Yes eller MergablePropertyAttribute.No.
Mer information finns i Attribut.
Konstruktorer
| Name | Description |
|---|---|
| MergablePropertyAttribute(Boolean) |
Initierar en ny instans av MergablePropertyAttribute klassen. |
Fält
| Name | Description |
|---|---|
| Default |
Anger standardvärdet, som är Yes, som är en egenskap som kan kombineras med egenskaper som tillhör andra objekt i en Properties window. Det här |
| No |
Anger att en egenskap inte kan kombineras med egenskaper som tillhör andra objekt i en Properties window. Det här |
| Yes |
Anger att en egenskap kan kombineras med egenskaper som tillhör andra objekt i en Properties window. Det här |
Egenskaper
| Name | Description |
|---|---|
| AllowMerge |
Hämtar ett värde som anger om den här egenskapen kan kombineras med egenskaper som tillhör andra objekt i en Properties window. |
| TypeId |
När den implementeras i en härledd klass hämtar du en unik identifierare för den här Attribute. (Ärvd från Attribute) |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Anger om den här instansen och ett angivet objekt är lika. |
| GetHashCode() |
Returnerar hash-koden för den här instansen. |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| IsDefaultAttribute() |
Avgör om det här attributet är standard. |
| Match(Object) |
När den åsidosätts i en härledd klass returneras ett värde som anger om den här instansen är lika med ett angivet objekt. (Ärvd från Attribute) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Explicita gränssnittsimplementeringar
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mappar en uppsättning namn till en motsvarande uppsättning av sändningsidentifierare. (Ärvd från Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Hämtar typinformationen för ett objekt, som kan användas för att hämta typinformationen för ett gränssnitt. (Ärvd från Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Hämtar antalet typinformationsgränssnitt som ett objekt tillhandahåller (antingen 0 eller 1). (Ärvd från Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Ger åtkomst till egenskaper och metoder som exponeras av ett objekt. (Ärvd från Attribute) |