ConfigurationSection コンストラクター

定義

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 参照してください。

適用対象