Share via


ConfigurationSection Oluşturucu

Tanım

ConfigurationSection sınıfının yeni bir örneğini başlatır.

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

Örnekler

Aşağıdaki örnekte oluşturucunun nasıl kullanılacağı gösterilmektedir ConfigurationSection . Bu örnekte adlı CustomSectionözel bir bölüm sınıfı oluşturduğunuz varsayılır. Böyle bir sınıf örneği için bkz. sınıfa ConfigurationSection genel bakış.


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

Açıklamalar

Oluşturucuyu ConfigurationSection kullanmak için önce özel bir bölüm türü tanımlamanız gerekir. Bir örnek için bkz. sınıfa ConfigurationSection genel bakış.

Şunlara uygulanır