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
  • 相关阅读:
    ガリレオの苦悩 攪乱す 1
    magento -- 添加中国省份列表
    magento使用google analytics
    Magento导出订单同时导出产品信息
    如何修改WAMP数据库上传文件的大小及上传时间限制
    magento插件手动下载
    Magento的价格去掉小数点
    magento首页调用最新产品
    url重写技术
    magento添加分类属性
  • 原文地址:https://www.cnblogs.com/tansm/p/212499.html
Copyright © 2011-2022 走看看