DesignOnlyAttribute Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Especifica se uma propriedade só pode ser definida no momento do projeto.
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
- Atributos
Exemplos
O exemplo seguinte cria uma GetLanguage propriedade. A propriedade está 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 do DesignOnlyAttribute. Primeiro, o código recebe uma PropertyDescriptorCollection com todas as propriedades do objeto. De seguida, indexa para encontrar PropertyDescriptorCollection a GetLanguage propriedade. Depois, devolve os atributos dessa propriedade e guarda-os na variável de atributos.
O exemplo então imprime se a propriedade é designada apenas ao recuperá-la DesignOnlyAttribute do AttributeCollection, e escrevê-la no ecrã da consola.
// 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()))
Observações
Os membros marcados com o DesignOnlyAttribute conjunto true só podem ser definidos no momento do design. Normalmente, estas propriedades existem apenas em tempo de projeto e não correspondem a uma propriedade real no objeto em tempo de execução.
Membros que não têm atributo ou são marcados com o DesignOnlyAttribute conjunto para false podem ser definidos durante a execução. A predefinição é false.
Uma propriedade com o definido DesignOnlyAttribute para true tem o seu valor serializado para o ficheiro .resx em vez do InitializeComponent método.
Para obter mais informações, consulte Atributos.
Construtores
| Name | Description |
|---|---|
| DesignOnlyAttribute(Boolean) |
Inicializa uma nova instância da DesignOnlyAttribute classe. |
Campos
| Name | Description |
|---|---|
| Default |
Especifica o valor padrão para o DesignOnlyAttribute, que é No. Este |
| No |
Especifica que uma propriedade pode ser definida em tempo de conceção ou em tempo de execução. Este |
| Yes |
Especifica que uma propriedade só pode ser definida no momento do projeto. Este |
Propriedades
| Name | Description |
|---|---|
| IsDesignOnly |
Obtém um valor que indica se uma propriedade só pode ser definida no momento do projeto. |
| 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 DesignOnlyAttribute. |
| GetHashCode() |
Devolve o código de hash para esta instância. |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| IsDefaultAttribute() |
Determina se este atributo é o padrão. |
| 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) |