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ındaki bilgileri konsola yazan bir konsol uygulamasıdır.

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

ShowSectionGroupCollectionInfo yöntemi bölüm grupları arasında yinelenir ve her biri için yöntemini çağırırShowSectionGroupInfo.

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 özyinelemeli 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. Tüm satırlar, satır kaydırmayı önlemek için metnin 79 karakteriyle sınırlıdır ve bu da mantıksal gruplandırmaları ayırt etmede 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ştirilebilir (bölüm grubu diğer bölüm gruplarını ve bölümleri 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. ve Sections özelliklerini kullanarak SectionGroups bir ConfigurationSectionGroup nesnenin içerdiği bölümlere ve bölüm gruplarına erişebilirsiniz.

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

Oluşturucular

Name Description
ConfigurationSectionGroup()

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

Özellikler

Name Description
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şkilendirilmiş bölüm grubu adını alır.

SectionGroups

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

Sections

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

Type

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

Yöntemler

Name Description
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()

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

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

Geçerli Objectbasit bir kopyasını oluşturur.

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

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

ToString()

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

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.