ConfigurationSection 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ConfigurationSection 類別的新執行個體。
protected:
ConfigurationSection();
protected ConfigurationSection ();
Protected Sub New ()
範例
下列範例將示範如何使用這個 ConfigurationSection 建構函式。 此範例假設您已建立名為 的 CustomSection
自定義區段類別。 如需這類類別的範例,請參閱 ConfigurationSection 類別概觀。
// Create a custom section.
static void CreateSection()
{
try
{
CustomSection customSection;
// Get the current configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Create the section entry
// in the <configSections> and the
// related target section in <configuration>.
if (config.Sections["CustomSection"] == null)
{
customSection = new CustomSection();
config.Sections.Add("CustomSection", customSection);
customSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
' Create a custom section.
Shared Sub CreateSection()
Try
Dim customSection As CustomSection
' Get the current configuration file.
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Create the section entry
' in the <configSections> and the
' related target section in <configuration>.
If config.Sections("CustomSection") Is Nothing Then
customSection = New CustomSection()
config.Sections.Add("CustomSection", customSection)
customSection.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
End If
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
備註
若要使用建 ConfigurationSection 構函式,您必須先定義自定義區段類型。 如需範例,請參閱 類別概 ConfigurationSection 觀。