zoukankan      html  css  js  c++  java
  • .config 自定义配置节 【转载】

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>    
        <section name="EncryptionMethod"  type="System.Configuration.DictionarySectionHandler, System,  Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" restartOnExternalChanges="false" />   <!--此处配置信息注意写全-->

        <section name="Mod"  type="System.Configuration.DictionarySectionHandler, System,  Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" restartOnExternalChanges="false" />  <!--此处配置信息注意写全-->
        
        <sectionGroup name="mySectionGroup"> <!--多了组的概念-->
          <section name="mySection" type="System.Configuration.NameValueSectionHandler" />         
        </sectionGroup>

     </configSections>

      <EncryptionMethod>
          <add key="Decrypt" value = "0"/>
          <add key="Encrypt" value = "1"/>
      </EncryptionMethod>

      <Mod>
        <add key="a" value = "0"/>
        <add key="b" value = "1"/>    
      </Mod>

      <mySectionGroup>
        <mySection>
          <add key="c" value = "0"/>
          <add key="d" value = "1"/>
        </mySection>    
      </mySectionGroup>

    </configuration>


        //使用 NameValueSectionHandler 或 DictionarySectionHandler 类的自定义配置节定义设置
        //NameValueCollection 的读取
        NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("mySectionGroup/mySection");
        //DictionarySectionHandler 的读取 
        IDictionary dict = ConfigurationManager.GetSection("EncryptionMethod") as IDictionary;
    DictionarySectionHandler的工作方式与NameValueFileSectionHandler几乎相同,其区别是DictionarySectionHandler返回HashTable对象,而不是Object。
  • 相关阅读:
    python基础之====函数对象、函数嵌套、名称空间与作用域、装饰器
    python基础之函数基础
    pytho基础之文件处理
    python基础之字符编码
    python基础之数据类型与变量
    python基础之核心风格
    函数
    数据类型、字符编码、文件处理
    MongoDB
    Shell学习(三)——Shell条件控制和循环语句
  • 原文地址:https://www.cnblogs.com/haibin168/p/2032126.html
Copyright © 2011-2022 走看看