ConfigurationSection Konstruktor

Definicja

Inicjuje nowe wystąpienie klasy ConfigurationSection.

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

Przykłady

W poniższym przykładzie pokazano, jak używać konstruktora ConfigurationSection . W tym przykładzie założono, że utworzono niestandardową klasę sekcji o nazwie CustomSection. Aby zapoznać się z przykładem takiej klasy, zobacz ConfigurationSection omówienie klasy.


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

Uwagi

Aby użyć konstruktora ConfigurationSection , należy najpierw zdefiniować niestandardowy typ sekcji. Aby zapoznać się z przykładem, ConfigurationSection zobacz omówienie klasy.

Dotyczy