DesignOnlyAttribute Class
Specifies whether a property can only be set at design time.
For a list of all members of this type, see DesignOnlyAttribute Members.
System.Object
System.Attribute
System.ComponentModel.DesignOnlyAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.All)> NotInheritable Public Class DesignOnlyAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.All)] public sealed class DesignOnlyAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::All)] public __gc __sealed class DesignOnlyAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.All) class DesignOnlyAttribute extends Attribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
Members marked with the DesignOnlyAttribute constructor of the value true can be set only at design time. Typically, these properties exist only at design time and do not correspond to a real property on the object at run time.
Members that either have no attribute or are marked with the DesignOnlyAttribute constructor of the value false can be set during run time. The default is false.
For more information, see Attributes Overview and Extending Metadata Using Attributes.
Example
[Visual Basic, C#, C++] The following example creates a GetLanguage property. The property is marked with a DesignOnlyAttribute.
[Visual Basic] <DesignOnly(True)> _ Public Property GetLanguage() As CultureInfo Get ' Insert code here. Return myCultureInfo End Get Set ' Insert code here. End Set End Property [C#] [DesignOnly(true)] public CultureInfo GetLanguage { get { // Insert code here. return myCultureInfo; } set { // Insert code here. } } [C++] public: [DesignOnly(true)] __property CultureInfo* get_GetLanguage() { // Insert code here. return myCultureInfo; } __property void set_GetLanguage( CultureInfo* value ) { // Insert code here. }
[Visual Basic, C#, C++] The next example gets the value of the DesignOnlyAttribute. First the code gets a PropertyDescriptorCollection with all the properties for the object. Next it indexes into the PropertyDescriptorCollection to find the GetLanguage property. Then it returns the attributes for this property and saves them in the attributes variable.
[Visual Basic, C#, C++] The example then prints whether the property is design only by retrieving DesignOnlyAttribute from the AttributeCollection, and writing it to the console screen.
[Visual Basic] ' Gets the attributes for the property. Dim attributes As AttributeCollection = _ TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes ' Prints the description by retrieving the DescriptionAttribute ' from the AttributeCollection. Dim myAttribute As DesignOnlyAttribute = _ CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute) Console.WriteLine(("This property is design only :" & _ myAttribute.IsDesignOnly.ToString())) [C#] // Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes; /* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DesignOnlyAttribute myAttribute = (DesignOnlyAttribute)attributes[typeof(DesignOnlyAttribute)]; Console.WriteLine("This property is design only :" + myAttribute.IsDesignOnly.ToString()); [C++] // Gets the attributes for the property. AttributeCollection* attributes = TypeDescriptor::GetProperties(this)->Item[S"GetLanguage"]->Attributes; /* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DesignOnlyAttribute* myAttribute = dynamic_cast<DesignOnlyAttribute*>(attributes->Item[__typeof(DesignOnlyAttribute)]); Console::WriteLine(S"This property is design only :{0}", __box(myAttribute->IsDesignOnly));
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.ComponentModel
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
DesignOnlyAttribute Members | System.ComponentModel Namespace | Attribute | PropertyDescriptor