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 참조하세요.

적용 대상