秉承一天写一篇的精神...今天的我又来了.....什么??前面有一天两天漏了?? 哦..那天水浸啦...
写的虽然不是很多旷世巨作,不也相信也不是什么很垃圾的东西..比较都是些程序的积累...经验吧...
今天要现的是抽象配置工厂的实现
配置的实现:
public class ProvidersHanders : IConfigurationSectionHandler
{
IConfigurationSectionHandler 成员#region IConfigurationSectionHandler 成员
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
XmlSerializer ser = new XmlSerializer(typeof(ProvidersConfiguration));
return ser.Deserialize(new XmlNodeReader(section));
}
#endregion
}
实现configurationsectionhandler接口
【Serializable()】
【XmlRoot("ProvidersConfig")】
public class ProvidersConfiguration
{
private ProvidersCollection providers;
private static yansCache cache = yansCache.Instance;
public ProvidersCollection Providers
{
get { return providers; }
set { providers = value; }//代码效果参考:http://www.ezhiqi.com/zx/art_7276.html
}
public static ProvidersConfiguration GetConfig
{
get
{
if (null == cache【"ProvidersConfig"】)
{
cache.Max("ProvidersConfig", ConfigurationManager.GetSection("ProvidersConfig"));
}
return (ProvidersConfiguration)cache【"ProvidersConfig"】;
}
}//代码效果参考:http://www.ezhiqi.com/bx/art_2207.html
public static Type GetTypeByProviderName(string ProviderName)
{
foreach (SingleProvider sp in GetConfig.Providers)
{
if (sp.ProviderName == ProviderName)
{
return Type.GetType(sp.Type);
}
}
throw new ArgumentNullException("找不到类型:" + ProviderName);
return null;
}
}
配置读取
【Serializable()】
public class ProvidersCollection : CollectionBase
{
public virtual void Add(SingleProvider p)
{
InnerList.Add(p);
}//代码效果参考:http://www.ezhiqi.com/bx/art_1615.html
public SingleProvider this【int index】
{
get { return (SingleProvider)InnerList【index】; }
set { InnerList【index】 = value; }
}
}
配置集合
【Serializable()】
public class SingleProvider
{
private string type;
public