This documentation is archived and is not being maintained.

RecommendedAsConfigurableAttribute Class

Specifies that the property can be used as an application setting.

For a list of all members of this type, see RecommendedAsConfigurableAttribute Members.

System.Object
   System.Attribute
      System.ComponentModel.RecommendedAsConfigurableAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Property)>
Public Class RecommendedAsConfigurableAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Property)]
public class RecommendedAsConfigurableAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Property)]
public __gc class RecommendedAsConfigurableAttribute : public
   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Property)
class RecommendedAsConfigurableAttribute 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

Properties that are marked with the RecommendedAsConfigurableAttribute constructor of the value true display when you expand the ConfigurableProperties line in the Properties window in Visual Studio .NET. A property that has no recommended setting or that is marked with RecommendedAsConfigurableAttribute constructor of the value false is not shown and is an unlikely candidate for being an application setting. The default is false.

You can bind a property that does not have a RecommendedAsConfigurableAttribute to a setting in Visual Studio .NET by clicking the ellipsis button (...) under Settingsin the Propertieswindow and selecting the appropriate property from the list.

Note   When you mark a property with RecommendedAsConfigurableAttribute constructor of the value true, the value of this attribute is set to the constant member Yes. For a property marked with RecommendedAsConfigurableAttribute constructor of the value false, the value is No. Therefore, when you want to check the value of this attribute in your code, you must specify the attribute as RecommendedAsConfigurableAttribute.Yes or RecommendedAsConfigurableAttribute.No.

For more information, see Attributes Overview and Extending Metadata Using Attributes.

Example

[Visual Basic, C#, C++] The following example marks a property as usable as an application setting.

[Visual Basic] 
<RecommendedAsConfigurable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

[C#] 
[RecommendedAsConfigurable(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }

[C++] 
public:
    [RecommendedAsConfigurable(true)]
    __property int get_MyProperty() {
        // Insert code here.
        return 0;
    }
    __property void set_MyProperty( int /*value*/ ) {
        // Insert code here.
    }

[Visual Basic, C#, C++] The next example shows how to check the value of the RecommendedAsConfigurableAttribute for MyProperty. First the code gets a PropertyDescriptorCollection with all the properties for the object. Next it indexes into the PropertyDescriptorCollection to get MyProperty. Then it returns the attributes for this property and saves them in the attributes variable.

[Visual Basic, C#, C++] This example presents two different ways of checking the value of the RecommendedAsConfigurableAttribute. In the second code fragment, the example calls the Equals method. In the last code fragment, the example uses the RecommendedAsConfigurable property to check the value.

[Visual Basic] 
' Gets the attributes for the property.
Dim attributes As AttributeCollection = TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Checks to see if the value of the RecommendedAsConfigurableAttribute is Yes.
If attributes(GetType(RecommendedAsConfigurableAttribute)).Equals(RecommendedAsConfigurableAttribute.Yes) Then
    ' Insert code here.
End If 

' This is another way to see if the property is recommended as configurable.
Dim myAttribute As RecommendedAsConfigurableAttribute = _
    CType(attributes(GetType(RecommendedAsConfigurableAttribute)), RecommendedAsConfigurableAttribute)
If myAttribute.RecommendedAsConfigurable Then
    ' Insert code here.
End If

[C#] 
// Gets the attributes for the property.
AttributeCollection attributes = 
   TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
 
// Checks to see if the value of the RecommendedAsConfigurableAttribute is Yes.
if(attributes[typeof(RecommendedAsConfigurableAttribute)].Equals(RecommendedAsConfigurableAttribute.Yes)) {
   // Insert code here.
}
 
// This is another way to see if the property is recommended as configurable.
RecommendedAsConfigurableAttribute myAttribute = 
   (RecommendedAsConfigurableAttribute)attributes[typeof(RecommendedAsConfigurableAttribute)];
if(myAttribute.RecommendedAsConfigurable) {
   // Insert code here.
}

[C++] 
// Gets the attributes for the property.
AttributeCollection* attributes = 
    TypeDescriptor::GetProperties(this)->Item[S"MyProperty"]->Attributes;

// Checks to see if the value of the RecommendedAsConfigurableAttribute is Yes.
if(attributes->Item[__typeof(RecommendedAsConfigurableAttribute)]->Equals(RecommendedAsConfigurableAttribute::Yes)) {
    // Insert code here.
}

// This is another way to see if the property is recommended as configurable.
RecommendedAsConfigurableAttribute* myAttribute = 
    dynamic_cast<RecommendedAsConfigurableAttribute*>(attributes->Item[__typeof(RecommendedAsConfigurableAttribute)]);
if(myAttribute->RecommendedAsConfigurable) {
    // Insert code here.
}

[Visual Basic, C#, C++] If you marked a class with the RecommendedAsConfigurableAttribute, use the following code to check the value.

[Visual Basic] 
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(RecommendedAsConfigurableAttribute)).Equals(RecommendedAsConfigurableAttribute.Yes) Then
    ' Insert code here.
End If 

[C#] 
AttributeCollection attributes = 
   TypeDescriptor.GetAttributes(MyProperty);
if(attributes[typeof(RecommendedAsConfigurableAttribute)].Equals(RecommendedAsConfigurableAttribute.Yes)) {
   // Insert code here.
}

[C++] 
AttributeCollection* attributes = 
    TypeDescriptor::GetAttributes( __box(MyProperty));
if(attributes->Item[__typeof(RecommendedAsConfigurableAttribute)]->Equals(RecommendedAsConfigurableAttribute::Yes)) {
    // Insert code here.
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter 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

RecommendedAsConfigurableAttribute Members | System.ComponentModel Namespace | Attribute | PropertyDescriptor | AttributeCollection | PropertyDescriptorCollection

Show: