DefaultPropertyAttribute Classe
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica la proprietà predefinita per un componente.
public ref class DefaultPropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class DefaultPropertyAttribute : Attribute
public sealed class DefaultPropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type DefaultPropertyAttribute = class
inherit Attribute
type DefaultPropertyAttribute = class
inherit Attribute
Public NotInheritable Class DefaultPropertyAttribute
Inherits Attribute
- Ereditarietà
- Attributi
Nell'esempio seguente viene definito un controllo denominato MyControl
. La classe è contrassegnata con un DefaultPropertyAttribute oggetto che specifica MyProperty
come proprietà predefinita.
[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.
return 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
Nell'esempio seguente viene creata un'istanza di MyControl
. Ottiene quindi gli attributi per la classe , estrae DefaultPropertyAttributee stampa il nome della proprietà predefinita.
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 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 =
(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
Utilizzare la Name proprietà per ottenere il nome della proprietà predefinita.
Per altre informazioni, vedere Attributi.
Default |
Inizializza una nuova istanza della classe DefaultPropertyAttribute. |
Default |
Consente di specificare il valore predefinito per l'attributo DefaultPropertyAttribute, che è |
Name |
Ottiene il nome della proprietà predefinita per il componente a cui è associato questo attributo. |
Type |
Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute. (Ereditato da Attribute) |
Equals(Object) |
Specifica se il valore dell'oggetto specificato è uguale all'oggetto DefaultPropertyAttribute corrente. |
Get |
Restituisce il codice hash per l'istanza. |
Get |
Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
Is |
In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata. (Ereditato da Attribute) |
Match(Object) |
Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato. (Ereditato da Attribute) |
Memberwise |
Crea una copia superficiale dell'oggetto Object corrente. (Ereditato da Object) |
To |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
_Attribute. |
Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch. (Ereditato da Attribute) |
_Attribute. |
Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia. (Ereditato da Attribute) |
_Attribute. |
Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1). (Ereditato da Attribute) |
_Attribute. |
Fornisce l'accesso a proprietà e metodi esposti da un oggetto. (Ereditato da Attribute) |
Prodotto | Versioni |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Feedback su .NET
.NET è un progetto open source. Seleziona un collegamento per fornire feedback: