DefaultPropertyAttribute Classe

Definição

Especifica a propriedade padrão de um 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
Herança
DefaultPropertyAttribute
Atributos

Exemplos

O exemplo a seguir define um controle chamado MyControl. A classe é marcada com uma DefaultPropertyAttribute que especifica MyProperty como a 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.
          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

O exemplo a seguir cria uma instância de MyControl. Em seguida, ele obtém os atributos da classe, extrai e DefaultPropertyAttributeimprime o nome da propriedade padrão.

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

Comentários

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

Para obter mais informações, consulte Atributos.

Construtores

DefaultPropertyAttribute(String)

Inicializa uma nova instância da classe DefaultPropertyAttribute.

Campos

Default

Especifica o valor padrão para o DefaultPropertyAttribute, que é null. Esse campo static é somente leitura.

Propriedades

Name

Obtém o nome da propriedade padrão para o componente ao qual esse atributo é associado.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Retorna se o valor do objeto especificado é igual ao DefaultPropertyAttribute atual.

GetHashCode()

Retorna o código hash para a instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

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

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

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

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

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

(Herdado de Attribute)

Aplica-se a

Confira também