ConfigurationSectionGroup Sınıf

Tanım

Yapılandırma dosyasındaki ilgili bölümlerden oluşan bir grubu temsil eder.

public ref class ConfigurationSectionGroup
public class ConfigurationSectionGroup
type ConfigurationSectionGroup = class
Public Class ConfigurationSectionGroup
Devralma
ConfigurationSectionGroup
Türetilmiş

Örnekler

Aşağıdaki örnekte, yapılandırma ayarlarını almak için sınıfının nasıl kullanılacağı ConfigurationSectionGroup gösterilmektedir. Örnek, yapılandırma ayarlarını okuyan ve her yapılandırma bölümü grubu ve içindeki bölümler hakkında bilgileri konsola yazan bir konsol uygulamasıdır.

Main yöntemi yapılandırma ayarlarını bir Configuration nesneye yükler, nesnesinden Configuration koleksiyonu alır SectionGroups ve ardından bölüm özelliği değerlerini görüntülemek için yöntemini çağırırShowSectionGroupCollectionInfo.

yöntemi ShowSectionGroupCollectionInfo bölüm grupları aracılığıyla yinelenir ve her biri için yöntemini çağırır ShowSectionGroupInfo .

yöntemi bölüm ShowSectionGroupInfo grubunun adını, bazı özellik değerlerini ve içerdiği bölümlerin adlarını görüntüler. Bölüm grubu bölüm grupları içeriyorsa, bu yöntem bu bölüm gruplarını görüntülemek için yinelemeli olarak çağırır ShowSectionGroupCollectionInfo .

Alan indentLevel , mantıksal gruplandırmaları göstermek üzere görüntülenen çizgilerin sol tarafına boşluk eklemek için kullanılır. Satır kaydırmayı önlemek için tüm satırlar 79 karakterle sınırlıdır ve bu da mantıksal gruplandırmaların ayırt edilmesinde zorlanır.

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

Açıklamalar

Yapılandırma dosyalarındaki (Web.config dosyası gibi) ayarlar bölümler halinde düzenlenir. Bazı bölümler ilişkili olduğundan, bunları bir bölüm grubunda gruplandırmak genellikle kullanışlıdır. sınıfı, ConfigurationSectionGroup bir yapılandırma dosyasının sectionGroup öğesinde configSections tanımlandığında bölümleri gruplandırmak için kullanılan XML öğesini temsil eder. Bölüm grupları iç içe yerleştirilmiş olabilir (bölüm grubu diğer bölüm gruplarının yanı sıra bölümleri de içerebilir). Aşağıdaki örnekte, iç içe üç bölüm grubunu tanımlayan bir configSections öğe gösterilmektedir:

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

Yapılandırma sistemi yapılandırma dosyalarındaki ayarları nesnelere ConfigurationSectionGroup yükler. bir ConfigurationSectionGroup nesnenin Sections içerdiği bölümlere ve bölüm gruplarına erişmek için ve SectionGroups özelliklerini kullanabilirsiniz.

Yapılandırma dosyalarından bilgilere erişme hakkında daha fazla bilgi için sınıfına ConfigurationManager bakın.

Oluşturucular

ConfigurationSectionGroup()

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

Özellikler

IsDeclarationRequired

Bu ConfigurationSectionGroup nesne bildiriminin gerekli olup olmadığını gösteren bir değer alır.

IsDeclared

Bu ConfigurationSectionGroup nesnenin bildirilip bildirildiğini belirten bir değer alır.

Name

Bu ConfigurationSectionGroup nesnenin name özelliğini alır.

SectionGroupName

Bu ConfigurationSectionGroupile ilişkili bölüm grubu adını alır.

SectionGroups

Bu ConfigurationSectionGroup nesnenin ConfigurationSectionGroup alt öğesi olan tüm nesneleri içeren bir ConfigurationSectionGroupCollection nesnesi alır.

Sections

Bu ConfigurationSectionGroup nesnenin içindeki tüm ConfigurationSection nesneleri içeren bir ConfigurationSectionCollection nesnesi alır.

Type

Bu ConfigurationSectionGroup nesnenin türünü alır veya ayarlar.

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
ForceDeclaration()

Bu ConfigurationSectionGroup nesnenin bildirimini zorlar.

ForceDeclaration(Boolean)

Bu ConfigurationSectionGroup nesnenin bildirimini zorlar.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ShouldSerializeSectionGroupInTargetVersion(FrameworkName)

yapılandırma nesnesi hiyerarşisi .NET Framework belirtilen hedef sürümü için seri hale getirildiğinde geçerli ConfigurationSectionGroup örneğin seri hale getirilip getirilmeyeceğini gösterir.

ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.