• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
编写人生
写写代码,写写人生
博客园    首页    新随笔    联系   管理    订阅  订阅
实现自己的配置读取器
    [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
posted on 2005-08-11 13:46  编写人生  阅读(415)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3