zoukankan      html  css  js  c++  java
  • C# App.config 自定义 配置节

    1)App.config 

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="color"   type="System.Configuration.NameValueSectionHandler" />
       
     <section name="message" type="System.Configuration.DictionarySectionHandler"/>
        <section name="name"   type="System.Configuration.SingleTagSectionHandler"/>

      </configSections>
      <color>
        <add key="red"   value="#ff0000"/>
        <add key="green" value="#00ff00"/>
        <add key="blue"  value="#0000ff"/>
      </color>
      <message>
        <add key="welcome" value="你好,欢迎"/>
      </message>
      <name firstName="陈" lastName="明明"/>

    </configuration>

    对于自定义的配置节,应该先在 <configSections>中声明要配置的节与类型,如着色部分,接着,在后面定义要配置的具体内容,正如定义一个变量。

     (2)配置节的访问

           public static void Main(string[] args)
            {
                //get color
                NameValueCollection color = (NameValueCollection)ConfigurationManager.GetSection("color");
                foreach (String str in color.AllKeys) {
                    Console.WriteLine(str+":"+color[str]);
                }
                //get message
                IDictionary message = (IDictionary)ConfigurationManager.GetSection("message");
                foreach (String str in message.Keys) {
                    Console.WriteLine(str+":"+message[str]);
                }
                // get name
                IDictionary name = (IDictionary)ConfigurationManager.GetSection("name");
                foreach (String str in name.Keys)
                {
                    Console.WriteLine(str + ":" + name[str]);
                }   
                //Console.WriteLine(name["firstName"]);
                Console.Read();
            } 

    转转 http://www.cnblogs.com/zengle_love/archive/2009/03/22/1419138.html

  • 相关阅读:
    python爬虫,scrapy,获取响应的cookie,获取返回的cookie
    this指向
    闭包的10种形式
    nodejs 公私钥文件加密解密
    mysql基础知识
    nodejs 连接mysql 集群,开启事务,事务回滚封装
    pm2 启动eggjs,
    js身份证验证,二代身份证,大陆,权重验证,正规
    nodejs限制IP一段时间内的访问次数
    nodejs链接mysql集群,nodejs PoolCluster : Error: Too many connections
  • 原文地址:https://www.cnblogs.com/tianciliangen/p/5977289.html
Copyright © 2011-2022 走看看