ConfigurationSectionGroup ConfigurationSectionGroup ConfigurationSectionGroup ConfigurationSectionGroup Class

Definition

Stellt eine Gruppe verwandter Abschnitte innerhalb einer Konfigurationsdatei dar.Represents a group of related sections within a configuration file.

public ref class ConfigurationSectionGroup
public class ConfigurationSectionGroup
type ConfigurationSectionGroup = class
Public Class ConfigurationSectionGroup
Vererbung
ConfigurationSectionGroupConfigurationSectionGroupConfigurationSectionGroupConfigurationSectionGroup
Abgeleitet

Beispiele

Im folgenden Beispiel wird gezeigt, wie die ConfigurationSectionGroup -Klasse zum Abrufen von Konfigurationseinstellungen verwendet wird.The following example shows how to use the ConfigurationSectionGroup class to retrieve configuration settings. Das Beispiel ist eine Konsolenanwendung, die Konfigurationseinstellungen liest und Informationen zu jeder Konfigurations Abschnitts Gruppe und den darin beschriebenen Abschnitten in die Konsole schreibt.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.

Die Main -Methode lädt die Konfigurationseinstellungen in Configuration ein-Objekt, ruft SectionGroups die Auflistung aus Configuration dem-Objekt ab und ruft ShowSectionGroupCollectionInfo dann die-Methode auf, um die Abschnitts Eigenschaftswerte anzuzeigen.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.

Die ShowSectionGroupCollectionInfo -Methode durchläuft die Abschnitts Gruppen und ruft die ShowSectionGroupInfo -Methode für jedes einzelne auf.The ShowSectionGroupCollectionInfo method iterates through the section groups and calls the ShowSectionGroupInfo method for each one.

Die ShowSectionGroupInfo -Methode zeigt den Namen der Abschnitts Gruppe, einige Eigenschaftswerte und die Namen der enthaltenen Abschnitte an.The ShowSectionGroupInfo method displays the name of the section group, some property values, and the names of the sections that it contains. Wenn die Abschnitts Gruppe Abschnitts Gruppen enthält, ruft ShowSectionGroupCollectionInfo diese Methode rekursiv auf, um diese Abschnitts Gruppen anzuzeigen.If the section group contains section groups, this method calls ShowSectionGroupCollectionInfo recursively to display those section groups.

Das indentLevel -Feld wird zum Hinzufügen von Leerzeichen auf der linken Seite der angezeigten Zeilen verwendet, um logische Gruppierungen anzuzeigen.The indentLevel field is used to add spaces to the left side of displayed lines to show logical groupings. Alle Zeilen sind auf 79 Textzeichen beschränkt, um Zeilenumbrüche zu vermeiden. Dadurch wird die Unterscheidung der logischen Gruppierungen erschwert.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

Hinweise

Einstellungen in Konfigurationsdateien (z. b. die Datei "Web. config") werden in Abschnitte organisiert.Settings in configuration files (such as the Web.config file) are organized into sections. Da einige Abschnitte verwandt sind, ist es häufig sinnvoll, Sie in einer Abschnitts Gruppe zu gruppieren.Because some sections are related, it is often convenient to group them in a section group. Die ConfigurationSectionGroup -Klasse stellt sectionGroup das XML-Element dar, das zum Gruppieren von Abschnitten verwendet wird, configSections Wenn Sie im-Element einer Konfigurationsdatei definiert werden.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. Abschnitts Gruppen können gruppiert werden (eine Abschnitts Gruppe kann andere Abschnitts Gruppen und Abschnitte enthalten).Section groups can be nested (a section group can contain other section groups as well as sections). Das folgende Beispiel zeigt ein configSections -Element, das drei Gruppen von Gruppen von Gruppen definiert: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>  

Das Konfigurationssystem lädt Einstellungen aus Konfigurationsdateien in ConfigurationSectionGroup Objekte.The configuration system loads settings from configuration files into ConfigurationSectionGroup objects. Sie können die- Sections Eigenschaft SectionGroups und die-Eigenschaft verwenden, um auf die Abschnitte und Abschnitts Gruppen ConfigurationSectionGroup zuzugreifen, die in einem-Objekt enthalten sind.You can use the Sections and SectionGroups properties to access the sections and section groups that are contained in a ConfigurationSectionGroup object.

Weitere Informationen zum Zugreifen auf Informationen aus Konfigurationsdateien finden Sie in der ConfigurationManager -Klasse.For more information about how to access information from configuration files, see the ConfigurationManager class.

Konstruktoren

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

Initialisiert eine neue Instanz der ConfigurationSectionGroup-Klasse.Initializes a new instance of the ConfigurationSectionGroup class.

Eigenschaften

IsDeclarationRequired IsDeclarationRequired IsDeclarationRequired IsDeclarationRequired

Ruft einen Wert ab, der angibt, ob die Deklaration dieses ConfigurationSectionGroup-Objekts erforderlich ist.Gets a value that indicates whether this ConfigurationSectionGroup object declaration is required.

IsDeclared IsDeclared IsDeclared IsDeclared

Ruft einen Wert ab, der angibt, ob dieses ConfigurationSectionGroup-Objekt deklariert wird.Gets a value that indicates whether this ConfigurationSectionGroup object is declared.

Name Name Name Name

Ruft die Namenseigenschaft dieses ConfigurationSectionGroup-Objekts ab.Gets the name property of this ConfigurationSectionGroup object.

SectionGroupName SectionGroupName SectionGroupName SectionGroupName

Ruft den dieser ConfigurationSectionGroup zugeordneten Abschnittsgruppennamen ab.Gets the section group name associated with this ConfigurationSectionGroup.

SectionGroups SectionGroups SectionGroups SectionGroups

Ruft ein ConfigurationSectionGroupCollection-Objekt ab, das alle ConfigurationSectionGroup-Objekte enthält, die untergeordnete Elemente dieses ConfigurationSectionGroup-Objekts sind.Gets a ConfigurationSectionGroupCollection object that contains all the ConfigurationSectionGroup objects that are children of this ConfigurationSectionGroup object.

Sections Sections Sections Sections

Ruft ein ConfigurationSectionCollection-Objekt ab, das alle ConfigurationSection-Objekte innerhalb dieses ConfigurationSectionGroup-Objekts enthält.Gets a ConfigurationSectionCollection object that contains all of ConfigurationSection objects within this ConfigurationSectionGroup object.

Type Type Type Type

Ruft den Typ für dieses ConfigurationSectionGroup-Objekt ab oder legt diesen fest.Gets or sets the type for this ConfigurationSectionGroup object.

Methoden

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

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

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

Erzwingt die Deklaration für dieses ConfigurationSectionGroup-Objekt.Forces the declaration for this ConfigurationSectionGroup object.

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

Erzwingt die Deklaration für dieses ConfigurationSectionGroup-Objekt.Forces the declaration for this ConfigurationSectionGroup object.

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

Fungiert als Standardhashfunktion.Serves as the default hash function.

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

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

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

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

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

Gibt an, ob die aktuelle ConfigurationSectionGroup-Instanz serialisiert werden soll, wenn die Konfigurationsobjekthierarchie für die angegebene Zielversion von .NET Framework.NET Framework serialisiert wird.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()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Gilt für:

Siehe auch