DefaultPropertyAttribute Classe

Definição

Especifica a propriedade padrão para um componente.

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
Herança
DefaultPropertyAttribute
Atributos

Exemplos

O exemplo seguinte define um controlo chamado MyControl. A classe está marcada com um DefaultPropertyAttribute que especifica MyProperty como propriedade padrão.

[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

O exemplo seguinte cria uma instância de MyControl. Depois obtém os atributos da classe, extrai o DefaultPropertyAttribute, e imprime o nome da propriedade predefinida.

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

Observações

Use a Name propriedade para obter o nome da propriedade padrão.

Para obter mais informações, consulte Atributos.

Construtores

Name Description
DefaultPropertyAttribute(String)

Inicializa uma nova instância da DefaultPropertyAttribute classe.

Campos

Name Description
Default

Especifica o valor padrão para o DefaultPropertyAttribute, que é null. Este static campo é só de leitura.

Propriedades

Name Description
Name

Obtém o nome da propriedade padrão do componente ao qual este atributo está vinculado.

TypeId

Quando implementado numa classe derivada, obtém um identificador único para esta Attribute.

(Herdado de Attribute)

Métodos

Name Description
Equals(Object)

Devolve se o valor do objeto dado é igual à corrente DefaultPropertyAttribute.

GetHashCode()

Devolve o código de hash para esta instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando sobrescrito numa classe derivada, indica se o valor desta instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando sobrescrito numa classe derivada, devolve um valor que indica se esta instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Implementações de Interface Explícita

Name Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de despacho.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera a informação de tipo de um objeto, que pode ser usada para obter a informação de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera o número de interfaces de informações de tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Ver também