ConfigurationSectionGroup ConfigurationSectionGroup ConfigurationSectionGroup ConfigurationSectionGroup Class

Definizione

Rappresenta un gruppo di sezioni correlate all'interno di un file di configurazione.Represents a group of related sections within a configuration file.

public ref class ConfigurationSectionGroup
public class ConfigurationSectionGroup
type ConfigurationSectionGroup = class
Public Class ConfigurationSectionGroup
Ereditarietà
ConfigurationSectionGroupConfigurationSectionGroupConfigurationSectionGroupConfigurationSectionGroup
Derivato

Esempi

Nell'esempio seguente viene illustrato come utilizzare la ConfigurationSectionGroup classe per recuperare le impostazioni di configurazione.The following example shows how to use the ConfigurationSectionGroup class to retrieve configuration settings. L'esempio è un'applicazione console che legge le impostazioni di configurazione e scrive le informazioni su ogni gruppo di sezioni di configurazione e le sezioni nella console.The example is a console application that reads configuration settings and writes information about each configuration section group and the sections in it to the console.

Il Main metodo carica le impostazioni di configurazione in Configuration un oggetto, Configuration recupera SectionGroups la raccolta dall'oggetto, quindi chiama il ShowSectionGroupCollectionInfo metodo per visualizzare i valori delle proprietà della sezione.The Main method loads the configuration settings into a Configuration object, retrieves the SectionGroups collection from the Configuration object, and then calls the ShowSectionGroupCollectionInfo method to display the section property values.

Il ShowSectionGroupCollectionInfo metodo scorre i gruppi di sezioni e chiama il ShowSectionGroupInfo metodo per ciascuno di essi.The ShowSectionGroupCollectionInfo method iterates through the section groups and calls the ShowSectionGroupInfo method for each one.

Il ShowSectionGroupInfo metodo Visualizza il nome del gruppo di sezioni, alcuni valori di proprietà e i nomi delle sezioni che contiene.The ShowSectionGroupInfo method displays the name of the section group, some property values, and the names of the sections that it contains. Se il gruppo di sezioni contiene gruppi di sezioni, questo ShowSectionGroupCollectionInfo metodo chiama in modo ricorsivo per visualizzare tali gruppi di sezioni.If the section group contains section groups, this method calls ShowSectionGroupCollectionInfo recursively to display those section groups.

Il indentLevel campo viene utilizzato per aggiungere spazi al lato sinistro delle righe visualizzate per visualizzare i raggruppamenti logici.The indentLevel field is used to add spaces to the left side of displayed lines to show logical groupings. Tutte le righe sono limitate a 79 caratteri di testo per evitare il ritorno a capo riga, il che renderebbe più difficile distinguere i raggruppamenti logici.All lines are limited to 79 characters of text to avoid line wrapping, which would make it harder to distinguish the logical groupings.

using System;
using System.Collections;
using System.Configuration;

namespace Samples.AspNet
{
    class UsingConfigurationSectionGroup
    {
        static int indentLevel = 0;

        static void Main(string[] args)
        {

            // Get the application configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

            // Get the collection of the section groups.
            ConfigurationSectionGroupCollection sectionGroups =
                config.SectionGroups;

            // Display the section groups.
            ShowSectionGroupCollectionInfo(sectionGroups);
        }

        static void ShowSectionGroupCollectionInfo(
            ConfigurationSectionGroupCollection sectionGroups)
        {
            foreach (ConfigurationSectionGroup sectionGroup in sectionGroups)
            {
                ShowSectionGroupInfo(sectionGroup);
            }
        }

        static void ShowSectionGroupInfo(
            ConfigurationSectionGroup sectionGroup)
        {
            // Get the section group name.
            indent("Section Group Name: " + sectionGroup.Name);

            // Get the fully qualified group name.
            indent("Section Group Name: " + sectionGroup.SectionGroupName);

            indentLevel++;

            indent("Type: " + sectionGroup.Type);
            indent("Is Group Required?: " + 
                sectionGroup.IsDeclarationRequired);
            indent("Is Group Declared?: " + sectionGroup.IsDeclared);
            indent("Contained Sections:");

            indentLevel++;
            foreach (ConfigurationSection section 
                in sectionGroup.Sections)
            {
                indent("Section Name:" + section.SectionInformation.Name);
            }
            indentLevel--;

            // Display contained section groups if there are any.
            if (sectionGroup.SectionGroups.Count > 0)
            {
                indent("Contained Section Groups:");

                indentLevel++;
                ConfigurationSectionGroupCollection sectionGroups =
                    sectionGroup.SectionGroups;
                ShowSectionGroupCollectionInfo(sectionGroups);
            }

            Console.WriteLine("");
            indentLevel--;
        }

        static void indent(string text)
        {
            for (int i = 0; i < indentLevel; i++)
            {
                Console.Write("  ");
            }
            Console.WriteLine(text.Substring(0, Math.Min(79 - indentLevel * 2, text.Length)));
        }
    }

}
Imports System.Collections
Imports System.Configuration

Class UsingConfigurationSectionGroup
   Private Shared indentLevel As Integer = 0
    
    Public Shared Sub Main(ByVal args() As String)

        ' Get the application configuration file.
        Dim config As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)

        ' Get the collection of the section groups.
        Dim sectionGroups As ConfigurationSectionGroupCollection = _
            config.SectionGroups

        ' Display the section groups.
        ShowSectionGroupCollectionInfo(sectionGroups)
    End Sub

    Shared Sub ShowSectionGroupCollectionInfo( _
        ByVal sectionGroups _
        As ConfigurationSectionGroupCollection)

        Dim group As ConfigurationSectionGroup
        For Each group In sectionGroups
            ShowSectionGroupInfo(group)
        Next group
    End Sub

    Shared Sub ShowSectionGroupInfo( _
    ByVal sectionGroup As ConfigurationSectionGroup)
        ' Get the section group name.
        indent("Section Group Name: " + sectionGroup.Name)

        ' Get the fully qualified section group name.
        indent("Section Group Name: " + sectionGroup.SectionGroupName)

        indentLevel += 1

        indent("Type: " + sectionGroup.Type)
        indent("Is Group Required?: " + _
           sectionGroup.IsDeclarationRequired.ToString())
        indent("Is Group Declared?: " + _
            sectionGroup.IsDeclared.ToString())
        indent("Contained Sections:")

        indentLevel += 1
        Dim section As ConfigurationSection
        For Each section In sectionGroup.Sections
            indent("Section Name:" + section.SectionInformation.Name)
        Next section
        indentLevel -= 1

        If (sectionGroup.SectionGroups.Count > 0) Then
            indent("Contained Section Groups:")

            indentLevel += 1
            Dim sectionGroups As ConfigurationSectionGroupCollection = _
                sectionGroup.SectionGroups
            ShowSectionGroupCollectionInfo(sectionGroups)
            indentLevel -= 1
        End If

        indent("")
        indentLevel -= 1

    End Sub
    Shared Sub indent(ByVal text As String)
        Dim i As Integer
        For i = 0 To indentLevel - 1
            Console.Write("  ")
        Next i
        Console.WriteLine(Left(text, 79 - indentLevel * 2))
    End Sub

End Class 'UsingConfigurationSectionGroup 

Commenti

Le impostazioni nei file di configurazione, ad esempio il file Web. config, sono organizzate in sezioni.Settings in configuration files (such as the Web.config file) are organized into sections. Poiché alcune sezioni sono correlate, è spesso utile raggrupparle in un gruppo di sezioni.Because some sections are related, it is often convenient to group them in a section group. La ConfigurationSectionGroup classe rappresenta l' sectionGroup elemento XML utilizzato per raggruppare le sezioni quando sono definite nell' configSections elemento di un file di configurazione.The ConfigurationSectionGroup class represents the sectionGroup XML element that is used to group sections when they are defined in the configSections element of a configuration file. I gruppi di sezioni possono essere annidati (un gruppo di sezioni può contenere altri gruppi di sezioni e sezioni).Section groups can be nested (a section group can contain other section groups as well as sections). Nell'esempio seguente viene illustrato configSections un elemento che definisce tre gruppi di sezioni annidate:The following example shows a configSections element that defines three nested section groups:

<configSections>  
  <sectionGroup name="system.web.extensions"...>  
    <sectionGroup name="scripting" ...>  
      <section name="scriptResourceHandler".../>  
      <sectionGroup name="webServices"...>  
        <section name="jsonSerialization" .../>  
        <section name="profileService" ... />        <section name="authenticationService" .../>  
        <section name="roleService" .../>  
      </sectionGroup>  
    </sectionGroup>  
  </sectionGroup>  
</configSections>  

Il sistema di configurazione carica le impostazioni dai file ConfigurationSectionGroup di configurazione in oggetti.The configuration system loads settings from configuration files into ConfigurationSectionGroup objects. È possibile utilizzare le Sections proprietà SectionGroups e per accedere alle sezioni e ai gruppi di sezioni contenuti in un ConfigurationSectionGroup oggetto.You can use the Sections and SectionGroups properties to access the sections and section groups that are contained in a ConfigurationSectionGroup object.

Per ulteriori informazioni su come accedere alle informazioni dai file di configurazione, vedere ConfigurationManager la classe.For more information about how to access information from configuration files, see the ConfigurationManager class.

Costruttori

ConfigurationSectionGroup() ConfigurationSectionGroup() ConfigurationSectionGroup() ConfigurationSectionGroup()

Inizializza una nuova istanza della classe ConfigurationSectionGroup.Initializes a new instance of the ConfigurationSectionGroup class.

Proprietà

IsDeclarationRequired IsDeclarationRequired IsDeclarationRequired IsDeclarationRequired

Ottiene un valore che indica se questa dichiarazione dell'oggetto ConfigurationSectionGroup è obbligatoria.Gets a value that indicates whether this ConfigurationSectionGroup object declaration is required.

IsDeclared IsDeclared IsDeclared IsDeclared

Ottiene un valore che indica se questo oggetto ConfigurationSectionGroup è dichiarato.Gets a value that indicates whether this ConfigurationSectionGroup object is declared.

Name Name Name Name

Ottiene la proprietà del nome di questo oggetto ConfigurationSectionGroup.Gets the name property of this ConfigurationSectionGroup object.

SectionGroupName SectionGroupName SectionGroupName SectionGroupName

Ottiene il nome del gruppo di sezioni associato a questa classe ConfigurationSectionGroup.Gets the section group name associated with this ConfigurationSectionGroup.

SectionGroups SectionGroups SectionGroups SectionGroups

Ottiene un oggetto ConfigurationSectionGroupCollection contenente tutti gli oggetti ConfigurationSectionGroup figli di questo oggetto ConfigurationSectionGroup.Gets a ConfigurationSectionGroupCollection object that contains all the ConfigurationSectionGroup objects that are children of this ConfigurationSectionGroup object.

Sections Sections Sections Sections

Ottiene un oggetto ConfigurationSectionCollection contenente tutti gli oggetti ConfigurationSection all'interno di questo oggetto ConfigurationSectionGroup.Gets a ConfigurationSectionCollection object that contains all of ConfigurationSection objects within this ConfigurationSectionGroup object.

Type Type Type Type

Ottiene o imposta il tipo di questo oggetto ConfigurationSectionGroup.Gets or sets the type for this ConfigurationSectionGroup object.

Metodi

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
ForceDeclaration() ForceDeclaration() ForceDeclaration() ForceDeclaration()

Impone la dichiarazione per questo oggetto ConfigurationSectionGroup.Forces the declaration for this ConfigurationSectionGroup object.

ForceDeclaration(Boolean) ForceDeclaration(Boolean) ForceDeclaration(Boolean) ForceDeclaration(Boolean)

Impone la dichiarazione per questo oggetto ConfigurationSectionGroup.Forces the declaration for this ConfigurationSectionGroup object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
ShouldSerializeSectionGroupInTargetVersion(FrameworkName) ShouldSerializeSectionGroupInTargetVersion(FrameworkName) ShouldSerializeSectionGroupInTargetVersion(FrameworkName) ShouldSerializeSectionGroupInTargetVersion(FrameworkName)

Indica se l'istanza corrente di ConfigurationSectionGroup deve essere serializzata quando viene serializzata la gerarchia di oggetti di configurazione per la versione di destinazione specificata di .NET Framework.NET Framework.Indicates whether the current ConfigurationSectionGroup instance should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework.NET Framework.

ToString() ToString() ToString() ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Inherited from Object)

Si applica a

Vedi anche