RecommendedAsConfigurableAttribute 类

注意:此类现在已过时。 非过时替代项是 SettingsBindableAttribute

指定该属性 (Property) 可以用作应用程序设置。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Property)> _
<ObsoleteAttribute("Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.")> _
Public Class RecommendedAsConfigurableAttribute
    Inherits Attribute
用法
Dim instance As RecommendedAsConfigurableAttribute
[AttributeUsageAttribute(AttributeTargets.Property)] 
[ObsoleteAttribute("Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.")] 
public class RecommendedAsConfigurableAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property)] 
[ObsoleteAttribute(L"Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.")] 
public ref class RecommendedAsConfigurableAttribute : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property) */ 
/** @attribute ObsoleteAttribute("Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.") */ 
public class RecommendedAsConfigurableAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Property) 
ObsoleteAttribute("Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.") 
public class RecommendedAsConfigurableAttribute extends Attribute

备注

展开“属性”窗口中的“ConfigurableProperties”行时,显示通过将 RecommendedAsConfigurableAttribute 设置为 true 进行标记的属性 (Property) 。没有建议设置的属性 (Property) 或通过将 RecommendedAsConfigurableAttribute 设置为 false 进行标记的属性 (Property) 不显示,也不大可能成为应用程序设置的候选设置。默认为 false

通过如下方法可以将没有 RecommendedAsConfigurableAttribute 的属性 (Property) 绑定到 Visual Studio .NET 的设置中:单击“属性”窗口中“设置”下的省略号按钮 (...),然后从列表中选择适当的属性 (Property)。

提示

当使用设置为 trueRecommendedAsConfigurableAttribute 标记某个属性 (Property) 时,此属性 (Attribute) 的值会被设置为常数成员 Yes。对于通过将 RecommendedAsConfigurableAttribute 设置为值 false 进行标记的属性 (Property),此值为 No。因此,若要检查代码中此属性 (Attribute) 的值,必须将该属性 (Attribute) 指定为 RecommendedAsConfigurableAttribute.YesRecommendedAsConfigurableAttribute.No

有关更多信息,请参见 属性 (Attribute) 概述利用属性扩展元数据

.

示例

下面的示例将属性标记为可以作为应用程序设置使用。

<RecommendedAsConfigurable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property
[RecommendedAsConfigurable(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }
public:
   [RecommendedAsConfigurable(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int /*value*/ )
      {
         // Insert code here.
      }
   }
/** @attribute RecommendedAsConfigurable(true)
 */
/** @property
 */
public int get_MyProperty()
{
    // Insert code here.
    return 0;
} //get_MyProperty

/** @property
 */
public void set_MyProperty(int value)
{
    // Insert code here.
} //set_MyProperty

下一个示例演示如何检查 MyPropertyRecommendedAsConfigurableAttribute 的值。首先,代码获取具有该对象的所有属性 (Property) 的 PropertyDescriptorCollection。接下来,对 PropertyDescriptorCollection 进行索引,以获取 MyProperty。然后它返回该属性 (Property) 的属性 (Attribute),并将它们保存到属性 (Attribute) 变量中。

该示例提供两种不同的方法来检查 RecommendedAsConfigurableAttribute 的值。在第二个代码段中,该示例调用 Equals 方法。在最后一个代码段中,该示例使用 RecommendedAsConfigurable 属性 (Property) 检查该值。

' 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
// 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.
}
// 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[ RecommendedAsConfigurableAttribute::typeid ]->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[ RecommendedAsConfigurableAttribute::typeid ]);
if ( myAttribute->RecommendedAsConfigurable )
{
   // Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this).get_Item(
    "MyProperty").get_Attributes();

// Checks to see if the value of the
// RecommendedAsConfigurableAttribute is Yes.
if (attributes.get_Item(RecommendedAsConfigurableAttribute.class.
    ToType()).Equals(RecommendedAsConfigurableAttribute.Yes)) {
    // Insert code here.
}

// This is another way to see if the property is recommended
// as configurable.
RecommendedAsConfigurableAttribute myAttribute =
    ((RecommendedAsConfigurableAttribute)(attributes.get_Item
    (RecommendedAsConfigurableAttribute.class.ToType())));

if (myAttribute.get_RecommendedAsConfigurable()) {
    // Insert code here.
}

如果将类标记为 RecommendedAsConfigurableAttribute,请使用下列代码检查该值。

Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(RecommendedAsConfigurableAttribute)).Equals(RecommendedAsConfigurableAttribute.Yes) Then
    ' Insert code here.
End If 
AttributeCollection attributes = 
   TypeDescriptor.GetAttributes(MyProperty);
if(attributes[typeof(RecommendedAsConfigurableAttribute)].Equals(RecommendedAsConfigurableAttribute.Yes)) {
   // Insert code here.
}
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ RecommendedAsConfigurableAttribute::typeid ]->Equals( RecommendedAsConfigurableAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes("MyProperty");

if (attributes.get_Item(RecommendedAsConfigurableAttribute.class.
    ToType()).Equals(RecommendedAsConfigurableAttribute.Yes)) {
        // Insert code here.
}

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.RecommendedAsConfigurableAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:1.0、1.1
在 2.0 中过时(编译器警告)

请参见

参考

RecommendedAsConfigurableAttribute 成员
System.ComponentModel 命名空间
Attribute
PropertyDescriptor 类
AttributeCollection 类
PropertyDescriptorCollection 类