增加配置节 /// /// <param name="localPath"></param> /// <param name="<em>configSection</em> /// <returns></returns> public bool Put(string localPath, string remotePath, string <em>configSection</em> try { var config = ConfigurationManager.GetSection(<em>configSection</em> false; } } public bool Delete(string fileType, string filepath, string <em>configSection</em> try { var config = ConfigurationManager.GetSection(<em>configSection</em>
: IUnityContainer container = new UnityContainer(); 7: UnityConfigurationSection configSection ConfigurationManager.GetSection(UnityConfigurationSection.SectionName) as UnityConfigurationSection; 8: if (null == configSection } 12: 13: if (string.IsNullOrEmpty(containerName)) 14: { 15: configSection.Configure (container); 16: } 17: else 18: { 19: configSection.Configure
下面就来说configSection制定的规则。 2、为什么需要自定义节点 说完configSections作用(帮助我们按照它的规则创建一系列自定义节点),接下来说所为什么需要自定义节点? type="ZC.DBUtility.WebSiteInfoHandler,ZC.DBUtility"/> </sectionGroup> </configSections> (1)、定义一个configSection (3)、最后定义section配置节,通过这个配置节设置自定义节点的名称和处理configSection的一般处理程序 注意:这个处理程序必须继承IConfigurationSectionHandler
空项目已经配置好了Web.config文件,主要是两个地方的改动: <configSections> <section name="FineUIMvc" type="FineUIMvc.<em>ConfigSection</em>
UnityContainer(); 21: //配置UnityContainer 22: UnityConfigurationSection configSection UnityConfigurationSection.SectionName) 23: as UnityConfigurationSection; 24: if (null == configSection = configSection ) 29: { 30: if(string.IsNullOrEmpty(containerName)) 31: { 32: configSection.Configure(container); 33: } 34: else 35: { 36: configSection.Configure
空项目已经配置好了Web.config文件,主要是两个地方的改动: <configSections> <section name="FineUIMvc" type="FineUIMvc.<em>ConfigSection</em>
要返回一个包含在section1中的key-value pairs的IConfigurationSection,调用GetSection并且应用section name: var configSection = _config.GetSection("section1"); 其中configSection没有value,只有一个key和path. 相似的,要包含key为section2:subsection0的value,调用GetSection并且应用section path: var configSection = _config.GetSection GetChildren 调用在section2上的IConfiguration.GetChildren包含: subsection0 subsection1 var configSection = _config.GetSection ("section2"); var children = configSection.GetChildren(); Exists 用ConfigurationExtensions.Exists来确定configuration
注意到Web.Config中没有configSection结点的设置,也就是并没有定义appSettings结点该如何处理。 .Net已经提供了很多内置的处理程序,为了避免发生这个错误,我们必须在configSection中指定对mailServer结点的处理程序。 System.Configuration.SingleTagSectionHandler时,调用GetSection()方法会返回一个Hashtable(当调用GetSection()方法时,会潜在地执行configSection