Mic*_*tum 5 .net configuration app-config web-config
我有两个.config文件,我需要一个System.Configuration.Configuration,它们之间是部分合并?
我可以将文件作为XML读取并轻松创建所需的合并,但它是一个字符串或XDocument.但是,.net的System.Configuration似乎是严格基于文件的,所以我必须将它写入我想避免的临时目录.
有没有办法做到这一点?
示例config1.config
:
<configuration>
<appSettings>
<add key="CacheTime" value="300" />
</appSettings>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="MyBehavior">
<!-- snipped -->
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
并且config2.config
:
<configuration>
<system.serviceModel>
<client>
<endpoint name="MyEndpoint" address="net.tcp://...."
behaviorConfiguration="MyBehavior" binding="netTcpBinding"
contract="IMyContract">
</endpoint>
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
结果配置应该是这两者的联合,这样我就有了AppSetting和Endpoint.现在,这个例子包含WCF,但我不是在寻找一个特定于WCF的解决方案,因为我绝对需要一个System.Configuration.Configuration对象.
config1和config2只是示例 - 它们的实际组合是非确定性的,我可能有config1和config4或config 3和config4或config2和config3.