RecommendedAsConfigurableAttribute 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
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
- 繼承
- 屬性
下列範例會將屬性標示為可做為應用程式設定。
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
的屬性。 沒有建議設定或標示 RecommendedAsConfigurableAttribute 為 false
的屬性不會顯示,而且不太可能是應用程式設定的候選專案。 預設為 false
。
您可以按下 [屬性] 視窗中 [設定] 底下的省略號按鈕 (...) ,然後從清單中選取適當的屬性,將沒有 RecommendedAsConfigurableAttribute 屬性的屬性系結至 Visual Studio 中的設定。
注意
當您將 屬性 RecommendedAsConfigurableAttribute 標示為 true
時,這個屬性的值會設定為常數成員 Yes。 對於標示 RecommendedAsConfigurableAttribute 為 value false
的屬性,此值為 No。 因此,當您要在程式碼中檢查此屬性的值時,必須將 屬性指定為 RecommendedAsConfigurableAttribute.Yes 或 RecommendedAsConfigurableAttribute.No。
如需詳細資訊,請參閱屬性。
.
Recommended |
已淘汰.
已淘汰.
初始化 RecommendedAsConfigurableAttribute 類別的新執行個體。 |
Default |
已淘汰.
已淘汰.
指定 RecommendedAsConfigurableAttribute 的預設值,就是 No。 這個 |
No |
已淘汰.
已淘汰.
指定無法用來做為應用程式設定的屬性。 這個 |
Yes |
已淘汰.
已淘汰.
指定可用來做為應用程式設定的屬性。 這個 |
Recommended |
已淘汰.
已淘汰.
取得值,表示這個屬性 (Attribute) 繫結的屬性 (Property) 是否可用來做為應用程式設定。 |
Type |
已淘汰.
已淘汰.
在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。 (繼承來源 Attribute) |
Equals(Object) |
已淘汰.
已淘汰.
指示這個執行個體和指定的物件是否相等。 |
Get |
已淘汰.
已淘汰.
傳回這個執行個體的雜湊碼。 |
Get |
已淘汰.
已淘汰.
取得目前執行個體的 Type。 (繼承來源 Object) |
Is |
已淘汰.
已淘汰.
表示此執行個體的值是否為此類別的預設值。 |
Match(Object) |
已淘汰.
已淘汰.
在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。 (繼承來源 Attribute) |
Memberwise |
已淘汰.
已淘汰.
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
已淘汰.
已淘汰.
傳回代表目前物件的字串。 (繼承來源 Object) |
_Attribute. |
已淘汰.
已淘汰.
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
_Attribute. |
已淘汰.
已淘汰.
擷取物件的類型資訊,可以用來取得介面的類型資訊。 (繼承來源 Attribute) |
_Attribute. |
已淘汰.
已淘汰.
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
_Attribute. |
已淘汰.
已淘汰.
提供物件所公開的屬性和方法的存取權。 (繼承來源 Attribute) |
產品 | 版本 (已淘汰) |
---|---|
.NET | 6 (Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 7, 8, 9) |
.NET Framework | 1.1 (2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1) |
.NET Standard | (2.0, 2.1) |