本文整理汇总了C#中System.Configuration.ConfigurationSectionGroup类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationSectionGroup类的具体用法?C# ConfigurationSectionGroup怎么用?C# ConfigurationSectionGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationSectionGroup类属于System.Configuration命名空间,在下文中一共展示了ConfigurationSectionGroup类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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)));
}
}
}