ConfigurationPropertyAttribute.IsKey 屬性

定義

取得或設定值,指出這項是否為裝飾的項目屬性之索引鍵屬性。

public:
 property bool IsKey { bool get(); void set(bool value); };
public bool IsKey { get; set; }
member this.IsKey : bool with get, set
Public Property IsKey As Boolean

屬性值

如果此屬性為集合項目的索引鍵屬性,則為 true,否則為 false。 預設為 false

範例

下列範例將示範如何使用 IsKey 屬性。

[ConfigurationProperty("name", DefaultValue = "Contoso",
    IsRequired = true, IsKey = true)]
public string Name
{
    get
    {
        return (string)this["name"];
    }
    set
    {
        this["name"] = value;
    }
}
<ConfigurationProperty("name", DefaultValue:="Contoso", IsRequired:=True, IsKey:=True)>
Public Property Name() As String
    Get
        Return CStr(Me("name"))
    End Get
    Set(ByVal value As String)
        Me("name") = value
    End Set
End Property

備註

只有在您裝飾的屬性是集合時,才會 IsKey 套用屬性。 如果屬性不是集合,它就不會有任何作用。 多個元素可以標示為 IsKey

適用於