2009-01-07 74 views

回答

5

肯定的,只是有一個configSource =「」屬性指向另一個文件同名的XML元素替換默認的配置文件中的部分...

...在年應用。配置或web.config中......

<configSections> 
     <section name="Connections" 
     type="BPA.AMP.Configuration.XmlConfigurator, BPA.AMP.Data.Config.DAL"/> 
     <section name="AutoProcessConfig" 
     type="BPA.AMP.Configuration.XmlConfigurator, BPA.AMP.Data.Config.DAL"/> 
    </configSections> 


    <Connections configSource="Config\Connections.config" /> 
    <AutoProcessConfig configSource="Config\AutoProcess.config" /> 

然後共同XML;配置類

public class XmlConfigurator : IConfigurationSectionHandler 
    { 
     public object Create(object parent, 
          object configContext, XmlNode section) 
     { 
      XPathNavigator xPN; 
      if (section == null || (xPN = section.CreateNavigator()) == null) 
       return null; 
      // --------------------------------------------------------- 
      Type sectionType = Type.GetType((string)xPN.Evaluate 
            ("string(@configType)")); 
      XmlSerializer xs = new XmlSerializer(sectionType); 
      return xs.Deserialize(new XmlNodeReader(section)); 
     } 
    } 
+0

祝福你,我的兒子。這完全是完全的壞話。 – 2009-01-07 17:37:41

+0

完全一樣,歡迎,老兄! – 2009-01-07 17:48:03

0

您可以手動做到這一點,通過打開文檔作爲一個XDocument,找到合適的部分並將其傳遞給您的配置節處理程序。

XDocument configDoc = XDocument.Load(alternateConfigFile); 

var section = configDoc.Descendants("sectionName").First(); 

var obj = sectionHandler.Create(null, null, section); 
相關問題