• 获取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>
  • 相关阅读:
    二分制--找最小值去重
    angular过滤 排序问题
    div+css背景渐变色代码
    angular中对象与字符串之间的转换
    AMD模块
    jquery.validate
    谈谈js中深度克隆和浅度克隆
    还在使用git吗?不妨来看看如何使用git管理版本
    闭包
    js复习
  • 原文地址:https://www.cnblogs.com/pnljs/p/3039908.html
Copyright © 2020-2023  润新知