RecommendedAsConfigurableAttribute 類別

定義

警告

Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.

警告

RecommendedAsConfigurableAttribute has been deprecated. Use System.ComponentModel.SettingsBindableAttribute instead.

指定可用來做為應用程式設定的屬性。

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
[System.AttributeUsage(System.AttributeTargets.Property)]
public class RecommendedAsConfigurableAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
[System.Obsolete("RecommendedAsConfigurableAttribute has been deprecated. Use System.ComponentModel.SettingsBindableAttribute instead.")]
public class RecommendedAsConfigurableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
[<System.Obsolete("Use System.ComponentModel.SettingsBindableAttribute instead to work with the new settings model.")>]
type RecommendedAsConfigurableAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type RecommendedAsConfigurableAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
[<System.Obsolete("RecommendedAsConfigurableAttribute has been deprecated. Use System.ComponentModel.SettingsBindableAttribute instead.")>]
type RecommendedAsConfigurableAttribute = class
    inherit Attribute
Public Class RecommendedAsConfigurableAttribute
Inherits Attribute
繼承
RecommendedAsConfigurableAttribute
屬性

範例

下列範例會將屬性標示為可做為應用程式設定。

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

下一個範例示範如何檢查 RecommendedAsConfigurableAttribute 的值。MyProperty 首先,程式代碼會取得 PropertyDescriptorCollection 具有物件之所有屬性的 。 接下來,它會編制索引到 PropertyDescriptorCollection ,以取得 MyProperty。 然後它會傳回此屬性的屬性,並將其儲存在屬性變數中。

此範例提供兩種不同的方法來檢查的值 RecommendedAsConfigurableAttribute。 在第二個代碼段中,此範例會呼叫 Equals 方法。 在最後一個代碼段中,此範例會 RecommendedAsConfigurable 使用 屬性來檢查值。

// 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,請使用下列程式代碼來檢查值。

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

備註

當您展開 [屬性] 視窗中的 [可設定][屬性] 行時,標示RecommendedAsConfigurableAttribute為要顯示之集合true的屬性。 沒有建議設定或標示 RecommendedAsConfigurableAttributefalse 的屬性不會顯示,而且不太可能是應用程式設定的候選專案。 預設為 false

您可以按下 [屬性] 視窗中 [設定] 底下的省略號按鈕 (...) ,然後從清單中選取適當的屬性,將沒有 RecommendedAsConfigurableAttribute 屬性的屬性系結至 Visual Studio 中的設定。

注意

當您將 屬性 RecommendedAsConfigurableAttribute 標示為 true時,這個屬性的值會設定為常數成員 Yes。 對於標示 RecommendedAsConfigurableAttribute 為 value false的屬性,此值為 No。 因此,當您要在程式碼中檢查此屬性的值時,必須將 屬性指定為 RecommendedAsConfigurableAttribute.YesRecommendedAsConfigurableAttribute.No

如需詳細資訊,請參閱屬性

.

建構函式

RecommendedAsConfigurableAttribute(Boolean)
已淘汰.
已淘汰.

初始化 RecommendedAsConfigurableAttribute 類別的新執行個體。

欄位

Default
已淘汰.
已淘汰.

指定 RecommendedAsConfigurableAttribute 的預設值,就是 No。 這個 static 欄位是唯讀的。

No
已淘汰.
已淘汰.

指定無法用來做為應用程式設定的屬性。 這個 static 欄位是唯讀的。

Yes
已淘汰.
已淘汰.

指定可用來做為應用程式設定的屬性。 這個 static 欄位是唯讀的。

屬性

RecommendedAsConfigurable
已淘汰.
已淘汰.

取得值,表示這個屬性 (Attribute) 繫結的屬性 (Property) 是否可用來做為應用程式設定。

TypeId
已淘汰.
已淘汰.

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)
已淘汰.
已淘汰.

指示這個執行個體和指定的物件是否相等。

GetHashCode()
已淘汰.
已淘汰.

傳回這個執行個體的雜湊碼。

GetType()
已淘汰.
已淘汰.

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()
已淘汰.
已淘汰.

表示此執行個體的值是否為此類別的預設值。

Match(Object)
已淘汰.
已淘汰.

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()
已淘汰.
已淘汰.

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()
已淘汰.
已淘汰.

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)
已淘汰.
已淘汰.

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)
已淘汰.
已淘汰.

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)
已淘汰.
已淘汰.

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)
已淘汰.
已淘汰.

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱