DefaultPropertyAttribute Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Egy összetevő alapértelmezett tulajdonságát adja meg.
public ref class DefaultPropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class DefaultPropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type DefaultPropertyAttribute = class
inherit Attribute
Public NotInheritable Class DefaultPropertyAttribute
Inherits Attribute
- Öröklődés
- Attribútumok
Példák
Az alábbi példa egy nevű vezérlőelemet MyControlhatároz meg. Az osztály alapértelmezett tulajdonságként megadott MyProperty tulajdonsággal DefaultPropertyAttribute van megjelölve.
[DefaultProperty("MyProperty")]
ref class MyControl: public Control
{
public:
property int MyProperty
{
int get()
{
// Insert code here.
return 0;
}
void set( int value )
{
// Insert code here.
}
}
// Insert any additional code.
};
[DefaultProperty("MyProperty")]
public class MyControl : Control
{
public int MyProperty
{
get =>
// Insert code here.
0;
set
{
// Insert code here.
}
}
// Insert any additional code.
}
<DefaultProperty("MyProperty")> _
Public Class MyControl
Inherits Control
Public Property MyProperty() As Integer
Get
' Insert code here.
Return 0
End Get
Set
' Insert code here.
End Set
End Property
' Insert any additional code.
End Class
A következő példa létrehoz egy példányt.MyControl Ezután lekéri az osztály attribútumait, kinyeri a DefaultPropertyAttribute, és kinyomtatja az alapértelmezett tulajdonság nevét.
int main()
{
// Creates a new control.
Form1::MyControl^ myNewControl = gcnew Form1::MyControl;
// Gets the attributes for the collection.
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewControl );
/* Prints the name of the default property by retrieving the
* DefaultPropertyAttribute from the AttributeCollection. */
DefaultPropertyAttribute^ myAttribute = dynamic_cast<DefaultPropertyAttribute^>(attributes[ DefaultPropertyAttribute::typeid ]);
Console::WriteLine( "The default property is: {0}", myAttribute->Name );
return 0;
}
public static int Main()
{
// Creates a new control.
MyControl myNewControl = new();
// Gets the attributes for the collection.
AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewControl);
/* Prints the name of the default property by retrieving the
* DefaultPropertyAttribute from the AttributeCollection. */
DefaultPropertyAttribute myAttribute =
(DefaultPropertyAttribute)attributes[typeof(DefaultPropertyAttribute)];
Console.WriteLine("The default property is: " + myAttribute.Name);
return 0;
}
Public Shared Function Main() As Integer
' Creates a new control.
Dim myNewControl As New MyControl()
' Gets the attributes for the collection.
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewControl)
' Prints the name of the default property by retrieving the
' DefaultPropertyAttribute from the AttributeCollection.
Dim myAttribute As DefaultPropertyAttribute = _
CType(attributes(GetType(DefaultPropertyAttribute)), DefaultPropertyAttribute)
Console.WriteLine(("The default property is: " + myAttribute.Name))
Return 0
End Function 'Main
Megjegyzések
Name A tulajdonság használatával kérje le az alapértelmezett tulajdonság nevét.
További információ: Attribútumok.
Konstruktorok
| Name | Description |
|---|---|
| DefaultPropertyAttribute(String) |
Inicializálja a DefaultPropertyAttribute osztály új példányát. |
Mezők
| Name | Description |
|---|---|
| Default |
Az alapértelmezett értéket adja meg a DefaultPropertyAttribute( vagyis |
Tulajdonságok
| Name | Description |
|---|---|
| Name |
Lekéri annak az összetevőnek az alapértelmezett tulajdonságát, amelyhez az attribútum kötve van. |
| TypeId |
Ha származtatott osztályban implementálják, ehhez egy egyedi azonosítót Attributekap. (Öröklődés forrása Attribute) |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Azt adja vissza, hogy az adott objektum értéke megegyezik-e az aktuális DefaultPropertyAttributeértékkel. |
| GetHashCode() |
A példány kivonatkódját adja vissza. |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| IsDefaultAttribute() |
Ha egy származtatott osztályban felül van bírálva, azt jelzi, hogy a példány értéke-e a származtatott osztály alapértelmezett értéke. (Öröklődés forrása Attribute) |
| Match(Object) |
Származtatott osztály felülírásakor egy olyan értéket ad vissza, amely jelzi, hogy ez a példány egy adott objektummal egyenlő-e. (Öröklődés forrása Attribute) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |
Explicit interfész-implementációk
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Névkészletet képez le a küldési azonosítók megfelelő készletére. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Lekéri egy objektum típusadatait, amelyek a felület típusadatainak lekérésére használhatók. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Lekéri az objektumok által biztosított típusinformációs felületek számát (0 vagy 1). (Öröklődés forrása Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Hozzáférést biztosít az objektumok által közzétett tulajdonságokhoz és metódusokhoz. (Öröklődés forrása Attribute) |