zoukankan      html  css  js  c++  java
  • 实现自己的配置读取器

        [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
        
    public class AddinSectionHandler : IConfigurationSectionHandler {
            
    public object Create(object parent, object context, XmlNode section) {
                List
    <AddinConfigItem> colItems;
                
    if (parent == null{
                    colItems 
    = new List<AddinConfigItem>();
                }

                
    else {
                    List
    <AddinConfigItem> colParent = (List<AddinConfigItem>)parent;
                    colItems 
    = new List<AddinConfigItem>(colParent);
                }

                AddinConfigItem item;
                
    foreach (XmlNode nodeItem in section.ChildNodes) {
                    item 
    = new AddinConfigItem();
                    item.DllFile 
    = nodeItem.Attributes["dllFile"].Value;
                    item.AddinClass 
    = nodeItem.Attributes["addinClass"].Value;
                    colItems.Add(item);
                }

                
    return colItems;
            }

        }


        
    public class AddinConfigItem {
            
    private string _dllFile;

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


            
    private string _addinClass;

            
    public string AddinClass {
                
    get return _addinClass; }
                
    set { _addinClass = value; }
            }

        }

    配置文件:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <configSections>
      <section name="Assemblys"
         type="Dcms.Common.AddinSectionHandler,Dcms.Common"/>
     </configSections>
     <Assemblys>
      <Assembly dllFile="a.dll" addinClass="a" />
      <Assembly dllFile="b.dll" addinClass="b" />
     </Assemblys>
    </configuration>
    参考文章:http://www.codeproject.com/aspnet/ConfigSections.asp
  • 相关阅读:
    Java数据类型转换(自动转换和强制转换)
    Java数据类型以及变量的定义
    Java8新特性_日期时间新类 LocalDate、LocalTime、LocalDateTime
    Java8新特性_接口中的默认方法
    java8 新特性 Optional容器类
    Java8新特性 并行流与串行流 Fork Join
    Java8新特性_stream API 练习
    IDEA导入JUnit4
    Reduce:规约;Collector:收集、判断性终止函数、组函数、分组、分区
    【Linux】排序命令sort
  • 原文地址:https://www.cnblogs.com/tansm/p/212499.html
Copyright © 2011-2022 走看看