DesignOnlyAttribute Classe

Definição

Especifica se uma propriedade só pode ser definida no momento do design.

public ref class DesignOnlyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class DesignOnlyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type DesignOnlyAttribute = class
    inherit Attribute
Public NotInheritable Class DesignOnlyAttribute
Inherits Attribute
Herança
DesignOnlyAttribute
Atributos

Exemplos

O exemplo a seguir cria uma GetLanguage propriedade. A propriedade é marcada com um DesignOnlyAttribute.

public:
   [DesignOnly(true)]
   property CultureInfo^ GetLanguage 
   {
      CultureInfo^ get()
      {
         // Insert code here.
         return myCultureInfo;
      }
      void set( CultureInfo^ value )
      {
         // Insert code here.
      }
   }
[DesignOnly(true)]
public CultureInfo GetLanguage
{
    get =>
        // Insert code here.
        myCultureInfo;
    set
    {
        // Insert code here.
    }
}
<DesignOnly(True)> _
Public Property GetLanguage() As CultureInfo
    Get
        ' Insert code here.
        Return myCultureInfo
    End Get
    Set
        ' Insert code here.
    End Set
End Property

O próximo exemplo obtém o valor da DesignOnlyAttribute. Primeiro, o código obtém uma PropertyDescriptorCollection com todas as propriedades do objeto. Em seguida, ele indexa na PropertyDescriptorCollection propriedade para localizar GetLanguage . Em seguida, retorna os atributos dessa propriedade e os salva na variável de atributos.

Em seguida, o exemplo imprime se a propriedade é design apenas recuperando-a AttributeCollectione gravando-a DesignOnlyAttribute na tela do console.

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "GetLanguage" ]->Attributes;

/* Prints whether the property is marked as DesignOnly 
by retrieving the DesignOnlyAttribute from the AttributeCollection. */
DesignOnlyAttribute^ myAttribute = dynamic_cast<DesignOnlyAttribute^>(attributes[ DesignOnlyAttribute::typeid ]);
Console::WriteLine( "This property is design only :{0}", myAttribute->IsDesignOnly );
// Gets the attributes for the property.
AttributeCollection attributes =
   TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes;

/* Prints whether the property is marked as DesignOnly 
 * by retrieving the DesignOnlyAttribute from the AttributeCollection. */
DesignOnlyAttribute myAttribute =
   (DesignOnlyAttribute)attributes[typeof(DesignOnlyAttribute)];
Console.WriteLine("This property is design only :" +
   myAttribute.IsDesignOnly.ToString());
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes

' Prints whether the property is marked as DesignOnly 
' by retrieving the DesignOnlyAttribute from the AttributeCollection.
Dim myAttribute As DesignOnlyAttribute = _
    CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute)
Console.WriteLine(("This property is design only :" & _
    myAttribute.IsDesignOnly.ToString()))

Comentários

Os membros marcados com o DesignOnlyAttribute conjunto a true ser definido somente no momento do design. Normalmente, essas propriedades existem apenas em tempo de design e não correspondem a uma propriedade real no objeto em tempo de execução.

Os membros que não têm atributo ou são marcados com o DesignOnlyAttribute conjunto a false serem definidos durante o tempo de execução. O padrão é false.

Uma propriedade com o DesignOnlyAttribute conjunto a true ter seu valor serializado para o arquivo .resx em vez do InitializeComponent método.

Para obter mais informações, consulte Atributos.

Construtores

Nome Description
DesignOnlyAttribute(Boolean)

Inicializa uma nova instância da classe DesignOnlyAttribute.

Campos

Nome Description
Default

Especifica o valor padrão para o DesignOnlyAttribute, que é No. Este static campo é somente leitura.

No

Especifica que uma propriedade pode ser definida em tempo de design ou em tempo de execução. Este static campo é somente leitura.

Yes

Especifica que uma propriedade só pode ser definida no momento do design. Este static campo é somente leitura.

Propriedades

Nome Description
IsDesignOnly

Obtém um valor que indica se uma propriedade pode ser definida somente em tempo de design.

TypeId

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

(Herdado de Attribute)

Métodos

Nome Description
Equals(Object)

Retorna se o valor do objeto fornecido é igual ao atual DesignOnlyAttribute.

GetHashCode()

Retorna o código hash dessa instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se esse atributo é o padrão.

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

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

Nome Description
_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 de um objeto, que podem ser usadas para obter as informações de tipo de 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