Bagikan melalui


ConfigurationSection Konstruktor

Definisi

Menginisialisasi instans baru kelas ConfigurationSection.

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

Contoh

Contoh berikut menunjukkan cara menggunakan ConfigurationSection konstruktor. Contoh ini mengasumsikan bahwa Anda telah membuat kelas bagian kustom bernama CustomSection. Untuk contoh kelas seperti itu ConfigurationSection , lihat gambaran umum kelas.


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

Keterangan

Untuk menggunakan ConfigurationSection konstruktor, Anda perlu menentukan jenis bagian kustom terlebih dahulu. Misalnya lihat gambaran ConfigurationSection umum kelas.

Berlaku untuk