SectionInformation.IsDeclared 属性

定义

获取一个值,指示是否已在配置文件中声明了关联的配置节。

public:
 property bool IsDeclared { bool get(); };
public bool IsDeclared { get; }
member this.IsDeclared : bool
Public ReadOnly Property IsDeclared As Boolean

属性值

如果此 ConfigurationSection 已在配置文件中声明,则为 true;否则为 false。 默认值为 true

示例

本部分中的示例演示如何在访问配置文件中的相关节信息后获取 IsDeclared 属性值。

以下示例获取 SectionInformation 对象。

// Get the current configuration file.
System.Configuration.Configuration config =
        ConfigurationManager.OpenExeConfiguration(
        ConfigurationUserLevel.None);

// Get the section.
UrlsSection section =
    (UrlsSection)config.GetSection("MyUrls");

SectionInformation sInfo =
    section.SectionInformation;
' Get the current configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)

' Get the section.
Dim section As UrlsSection = _
CType(config.GetSection("MyUrls"), UrlsSection)
        
Dim sInfo As SectionInformation = _
section.SectionInformation

以下示例获取 IsDeclared 值。

bool declared =
    sInfo.IsDeclared;
Console.WriteLine("Section declared?: {0}",
    declared.ToString());
Dim declared As Boolean = _
sInfo.IsDeclared
Console.WriteLine("Section declared?: {0}", _
declared.ToString())

适用于