Udostępnij za pośrednictwem


DefaultPropertyAttribute Klasa

Definicja

Określa właściwość domyślną składnika.

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
Dziedziczenie
DefaultPropertyAttribute
Atrybuty

Przykłady

W poniższym przykładzie zdefiniowano kontrolkę o nazwie MyControl. Klasa jest oznaczona znakiem DefaultPropertyAttribute , który określa MyProperty jako właściwość domyślną.

[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

W następnym przykładzie zostanie utworzone wystąpienie klasy MyControl. Następnie pobiera atrybuty klasy, wyodrębnia DefaultPropertyAttributeelement i wyświetla nazwę właściwości domyślnej.

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

Uwagi

Name Użyj właściwości , aby uzyskać nazwę właściwości domyślnej.

Aby uzyskać więcej informacji, zobacz Atrybuty.

Konstruktory

Nazwa Opis
DefaultPropertyAttribute(String)

Inicjuje nowe wystąpienie klasy DefaultPropertyAttribute.

Pola

Nazwa Opis
Default

Określa wartość domyślną elementu DefaultPropertyAttribute, czyli null. To static pole jest tylko do odczytu.

Właściwości

Nazwa Opis
Name

Pobiera nazwę właściwości domyślnej dla składnika, z którego jest powiązany ten atrybut.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attribute.

(Odziedziczone po Attribute)

Metody

Nazwa Opis
Equals(Object)

Zwraca, czy wartość danego obiektu jest równa bieżącej DefaultPropertyAttributewartości .

GetHashCode()

Zwraca kod skrótu dla tego wystąpienia.

GetType()

Pobiera Type bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Po zastąpieniu w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po zastąpieniu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Object.

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

Nazwa Opis
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do uzyskania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Zapewnia dostęp do właściwości i metod uwidocznionych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też