zoukankan      html  css  js  c++  java
  • 实现IConfigurationSectionHandler来获取自定义配置结构

    一 创建类AddinSectionHandler ,实现IConfigurationSectionHandler接口的Create方法
       public  class AddinSectionHandler : IConfigurationSectionHandler {
           
    IConfigurationSectionHandler 成员
       }

    二 增加一个这样的类

      public class AddinConfigItem {

            
    private string _addInClass;
            
    /// <summary>
            
    /// 添加服务类名称
            
    /// </summary>

            public string AddInClass {
                
    get return _addInClass; }
                
    set { _addInClass = value; }
            }


            
    private string _dllFile;
            
    /// <summary>
            
    /// 添加服务数据集名称
            
    /// </summary>

            public string DllFile {
                
    get return _dllFile; }
                
    set { _dllFile = value; }
            }


        }


    三 App.config中配置
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="ServerAssemblys" type="ConfigLoad.AddinSectionHandler,ConfigLoad"/>
      </configSections>
      <ServerAssemblys>
        <Assembly dllFile="111.dll" addinClass="aaa" />
        <Assembly dllFile="222.dll" addinClass="bbb" />
      </ServerAssemblys>
    </configuration>


    四 程序调用
     class Program {
            
    static void Main(string[] args) {
              
                
    //读取XML中服务节点的内容
                List<AddinConfigItem> lists = ConfigurationManager.GetSection("ServerAssemblys"as List<AddinConfigItem>;
                
    //加裁所有服务 
                foreach (AddinConfigItem item in lists) {

                }

            }

        }

    源码
  • 相关阅读:
    几个ID
    一百层高楼和两个棋子
    快速了解的链接 shell sed awk
    用shell实现一个“输入密码”程序
    i love you do you love me
    打造全新视觉环境
    【转】LINUX 环境变量总结
    TextBox输入限制
    获取CPU和硬盘序列号
    Lable属性设置(winform)
  • 原文地址:https://www.cnblogs.com/qiba78/p/1228540.html
Copyright © 2011-2022 走看看