DesignOnlyAttribute Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica se una proprietà può essere impostata solo in fase di progettazione.
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
- Ereditarietà
- Attributi
Esempio
Nell'esempio seguente viene creata una GetLanguage proprietà . La proprietà è contrassegnata con un oggetto 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
Nell'esempio seguente viene restituito il valore dell'oggetto DesignOnlyAttribute. Prima di tutto, il codice ottiene un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto . Successivamente, indicizza in PropertyDescriptorCollection per trovare la GetLanguage proprietà . Restituisce quindi gli attributi per questa proprietà e li salva nella variabile degli attributi.
Nell'esempio viene quindi stampato se la proprietà è progettata solo recuperando DesignOnlyAttribute da AttributeCollectione scrivendola nella schermata della 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()))
Commenti
I membri contrassegnati con il DesignOnlyAttribute set su true possono essere impostati solo in fase di progettazione. In genere, queste proprietà esistono solo in fase di progettazione e non corrispondono a una proprietà reale sull'oggetto in fase di esecuzione.
I membri che non dispongono di attributi o sono contrassegnati con il set su false possono essere impostati durante l'esecuzioneDesignOnlyAttribute. Il valore predefinito è false.
Una proprietà con il valore impostato su true ha il DesignOnlyAttribute relativo valore serializzato nel file resx anziché nel InitializeComponent metodo .
Per altre informazioni, vedere Attributi.
Costruttori
| Nome | Descrizione |
|---|---|
| DesignOnlyAttribute(Boolean) |
Inizializza una nuova istanza della classe DesignOnlyAttribute. |
Campi
| Nome | Descrizione |
|---|---|
| Default |
Specifica il valore predefinito per , DesignOnlyAttributeovvero No. Questo |
| No |
Specifica che una proprietà può essere impostata in fase di progettazione o in fase di esecuzione. Questo |
| Yes |
Specifica che una proprietà può essere impostata solo in fase di progettazione. Questo |
Proprietà
| Nome | Descrizione |
|---|---|
| IsDesignOnly |
Ottiene un valore che indica se una proprietà può essere impostata solo in fase di progettazione. |
| TypeId |
Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute. (Ereditato da Attribute) |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Restituisce un valore che indica se il valore dell'oggetto specificato è uguale all'oggetto corrente DesignOnlyAttribute. |
| GetHashCode() |
Restituisce il codice hash per questa istanza. |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| IsDefaultAttribute() |
Determina se questo attributo è l'impostazione predefinita. |
| Match(Object) |
Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato. (Ereditato da Attribute) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch. (Ereditato da Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia. (Ereditato da Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1). (Ereditato da Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto . (Ereditato da Attribute) |