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

下一個範例顯示如何檢查的值RecommendedAsConfigurableAttributeMyPropertyThe 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索引至MyProperty以取得。Next it indexes into the PropertyDescriptorCollection to get MyProperty. 然後, 它會傳回這個屬性的屬性, 並將其儲存在 attributes 變數中。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 

備註

當您展開 [屬性] 視窗中trueConfigurableProperties行時, 所標記的屬性會設定為 [ RecommendedAsConfigurableAttribute顯示]。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的屬性標示, 則值No為。For a property marked with RecommendedAsConfigurableAttribute set to value false, the value is No. 因此, 當您想要在程式碼中檢查這個屬性的值時, 您必須將屬性指定RecommendedAsConfigurableAttribute.YesRecommendedAsConfigurableAttribute.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.

執行個體時提供 SQL Server 登入。.

建構函式

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

取得值,表示這個屬性 (Attribute) 繫結的屬性 (Property) 是否可用來做為應用程式設定。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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。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)

適用於

另請參閱