zoukankan      html  css  js  c++  java
  • 获取App.Config中自定义的配置节点的信息

    C#代码

    View Code
     1 static void GetConfigInfo()
     2 {
     3     //访问Test1
     4     //IDictionary idTest1 = (IDictionary)ConfigurationSettings.GetConfig("Test1");
     5     IDictionary idTest1 = (IDictionary)System.Configuration.ConfigurationManager.GetSection("Test1");
     6     string str = (string)idTest1["setting1"] + "_____" + (string)idTest1["setting2"];
     7     Console.WriteLine(str);
     8 
     9     //访问配置节 Test2
    10     IDictionary idTest2 = (IDictionary)System.Configuration.ConfigurationManager.GetSection("Test2");            
    11     string[] keys = new string[idTest2.Keys.Count];
    12     string[] values = new string[idTest2.Keys.Count];
    13     idTest2.Keys.CopyTo(keys, 0);
    14     idTest2.Values.CopyTo(values, 0);
    15     Console.WriteLine(keys[0] + "_______________" + values[0]);
    16 }

    配置文件信息

    View Code
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <!--声明一个配置节,它的名字叫Test1,类型为...再设置配置节部分使用 <Test1 setting1= "Hello" setting2="World"/>它的第一个设置的值是Hello,第二个值是World,当然还可以更多-->
        <section name = "Test1" type="System.Configuration.SingleTagSectionHandler"/>
        <section name = "Test2" type ="System.Configuration.DictionarySectionHandler"/>
        <section name = "Test3" type="System.Configuration.NameValueSectionHandler" />
      </configSections>

      <Test1 setting1="Hello" setting2 ="World">
      </Test1>
      <Test2>
        <add key ="Hello1" value ="World"></add>
        <add key ="Hello2" value ="World"></add>
        <add key ="Hello3" value ="World"></add>
        <add key ="Hello4" value ="World"></add>
      </Test2>
      <Test3>
        <add key="Hello" value ="World"></add>
      </Test3>
      
      <appSettings>
        <add key="No1" value="GoldBuilder"/>
        <add key="No2" value="NormalBuilder"/>
      </appSettings>


    </configuration>
  • 相关阅读:
    开博的缘由
    听了一节公开课 课后感
    python中的函数、变量和递归函数
    迭代器和生成器
    字符串的格式化
    html和htm的区别
    基本数据类型总结
    数据类型-----集合
    基础测试题(字符串、列表、元组、字典)
    基本数据类型-----字典(Dictionary)
  • 原文地址:https://www.cnblogs.com/pnljs/p/3039908.html
Copyright © 2011-2022 走看看