ConfigurationSection ConfigurationSection ConfigurationSection Constructor

정의

ConfigurationSection 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ConfigurationSection class.

protected:
 ConfigurationSection();
protected ConfigurationSection ();
Protected Sub New ()

예제

다음 예제에서는 ConfigurationSection 생성자를 사용하는 방법을 보여 줍니다.The following example shows how to use the ConfigurationSection constructor. 이 예에서는 라는 사용자 지정 섹션 클래스를 만들었다고 가정 CustomSection합니다.This example assumes that you have created a custom section class named CustomSection. 이러한 클래스의 예 참조는 ConfigurationSection 클래스 개요입니다.For an example of such a class, see the ConfigurationSection class overview.


// 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 'CreateSection
 

설명

사용 하는 ConfigurationSection 먼저 사용자 지정 섹션 형식을 정의 해야 하는 생성자입니다.To use the ConfigurationSection constructor, you need to define a custom section type first. 예를 ConfigurationSection 클래스 개요입니다.For an example see the ConfigurationSection class overview.

적용 대상