ConfigurationPropertyAttribute.IsRequired 属性

定义

获取或设置一个值,该值指示经过修饰的元素属性是否为必需。

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

属性值

如果该属性是必需的,则为 true;否则为 false。 默认值为 false

示例

下面的示例演示如何使用 DefaultValue 属性。

[ConfigurationProperty("url", DefaultValue = "http://www.contoso.com",
    IsRequired = true)]
[RegexStringValidator(@"\w+:\/\/[\w.]+\S*")]
public string Url
{
    get
    {
        return (string)this["url"];
    }
    set
    {
        this["url"] = value;
    }
}
<ConfigurationProperty("url", DefaultValue:="http://www.contoso.com", IsRequired:=True), RegexStringValidator("\w+:\/\/[\w.]+\S*")>
Public Property Url() As String
    Get
        Return CStr(Me("url"))
    End Get
    Set(ByVal value As String)
        Me("url") = value
    End Set
End Property

适用于