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 za pomocą elementu 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.
          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

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

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

DefaultPropertyAttribute(String)

Inicjuje nowe wystąpienie klasy DefaultPropertyAttribute.

Pola

Default

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

Właściwości

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 Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

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

GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

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

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu 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 Objectelementu .

(Odziedziczone po Object)
ToString()

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

(Odziedziczone po Object)

Jawne implementacje interfejsu

_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 dla obiektu, który może służyć do pobierania 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)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też