RecommendedAsConfigurableAttribute 类

定义

警告

此 API 现已过时。

指定该属性可以用作应用程序设置。Specifies that the property can be used as an application setting.

public ref class RecommendedAsConfigurableAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
[System.Obsolete("Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.")]
public class RecommendedAsConfigurableAttribute : Attribute
type RecommendedAsConfigurableAttribute = class
    inherit Attribute
Public Class RecommendedAsConfigurableAttribute
Inherits Attribute
继承
RecommendedAsConfigurableAttribute
属性

示例

下面的示例将属性标记为可用作应用程序设置。The following example marks a property as usable as an application setting.

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

下一个示例演示如何检查 MyPropertyRecommendedAsConfigurableAttribute 的值。The next example shows how to check the value of the RecommendedAsConfigurableAttribute for MyProperty. 首先,代码获取一个 PropertyDescriptorCollection,其中包含对象的所有属性。First the code gets a PropertyDescriptorCollection with all the properties for the object. 接下来,它将索引到 PropertyDescriptorCollection 以获取 MyPropertyNext it indexes into the PropertyDescriptorCollection to get MyProperty. 然后,它将返回此属性的特性并将其保存在特性变量中。Then it returns the attributes for this property and saves them in the attributes variable.

此示例提供了两种不同的方法来检查 RecommendedAsConfigurableAttribute的值。This example presents two different ways of checking the value of the RecommendedAsConfigurableAttribute. 在第二个代码片段中,该示例调用 Equals 方法。In the second code fragment, the example calls the Equals method. 在上一个代码段中,该示例使用 RecommendedAsConfigurable 属性来检查值。In the last code fragment, the example uses the RecommendedAsConfigurable property to check the value.

// 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)["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.
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

如果使用 RecommendedAsConfigurableAttribute标记了类,请使用以下代码检查值。If you marked a class with the RecommendedAsConfigurableAttribute, use the following code to check the value.

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

注解

在 "属性" 窗口中展开 " ConfigurableProperties " 行时,将标记为 "RecommendedAsConfigurableAttribute" 设置为 "true 显示" 的属性。Properties that are marked with the RecommendedAsConfigurableAttribute set to true display when you expand the ConfigurableProperties line in the Properties window. 不会显示不推荐设置或标记为 RecommendedAsConfigurableAttribute 设置为 false 的属性,这不太可能成为应用程序设置。A property that has no recommended setting or that is marked with RecommendedAsConfigurableAttribute set to false is not shown and is an unlikely candidate for being an application setting. 默认值为 falseThe default is false.

通过单击 "属性" 窗口中 "设置" 下的省略号按钮(...)并从列表中选择相应的属性,可以将没有 RecommendedAsConfigurableAttribute 的属性绑定到 Visual Studio 中的设置。You can bind a property that does not have a RecommendedAsConfigurableAttribute to a setting in Visual Studio by clicking the ellipsis button (…) under Settings in the Properties window and selecting the appropriate property from the list.

备注

RecommendedAsConfigurableAttribute 设置为 true的属性标记时,此属性的值将设置为常量成员 YesWhen you mark a property with RecommendedAsConfigurableAttribute set to true, the value of this attribute is set to the constant member Yes. 对于标记为 RecommendedAsConfigurableAttribute 设置为 "value false" 的属性,值为 NoFor a property marked with RecommendedAsConfigurableAttribute set to value false, the value is No. 因此,当你想要在代码中检查此属性的值时,必须将属性指定为 RecommendedAsConfigurableAttribute.YesRecommendedAsConfigurableAttribute.NoTherefore, 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.

..

构造函数

RecommendedAsConfigurableAttribute(Boolean)

初始化 RecommendedAsConfigurableAttribute 类的新实例。Initializes a new instance of the RecommendedAsConfigurableAttribute class.

字段

Default

指定 RecommendedAsConfigurableAttribute 的默认值,即 NoSpecifies the default value for the RecommendedAsConfigurableAttribute, which is No. static 字段是只读的。This static field is read-only.

No

指定属性不能用作应用程序设置。Specifies that a property cannot be used as an application setting. static 字段是只读的。This static field is read-only.

Yes

指定属性能用作应用程序设置。Specifies that a property can be used as an application setting. static 字段是只读的。This static field is read-only.

属性

RecommendedAsConfigurable

获取一个值,该值指示该特性绑定到的属性是否可用作应用程序设置。Gets a value indicating whether the property this attribute is bound to can be used as an application setting.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

Equals(Object)

指示此实例和指定的对象是否相等。Indicates whether this instance and a specified object are equal.

GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

指示此实例的值是否为该类的默认值。Indicates whether the value of this instance is the default value for the class.

Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅