从流而不是文件加载配置文件
我使用 OpenMappedExeConfiguration 和 ExeConfigurationFileMap 来加载配置文件。它们的重载表明它们只适用于文件名。有没有办法从流加载配置文件?
背景:我想加载存储为嵌入式资源的配置文件。没有文件表示!
I use OpenMappedExeConfiguration with ExeConfigurationFileMap to load configuration files. Their overloads suggest that they only work with filenames. Is there a way to load a configuration file from a stream?
Background: I want to load configuration files that are stored as embedded resources. There is no file representation!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
否。 问题在于此类本身不读取配置。文件路径本身最终被Configuration类用来加载配置,而这个类实际上需要一个物理路径。
我认为唯一的解决方案是将文件存储到临时路径并从那里读取它。
No. The problem is that this class itself do not read the configuration. The file path itself is eventually used by the
Configuration
class to load the configuration, and this class actually wants a physical path.I think the only solution is to store the file to a temporary path and read it from there.
是。如果您的应用程序被允许更改应用程序文件夹中的文件 - 通过文件 IO 操作或执行“
更新*.config
文件代码>/保存
/刷新
”。该解决方案有直接的逻辑 - 想要进行远程配置吗?从远程获取,更新本地并拥有它。示例:假设您已将 wcf 部分的组(
、
.. 等)存储在文件wcfsections.test.config 中
(当然任何远程源都是可能的)并且想要“重载”conf 文件配置。然后配置更新/保存/刷新代码如下所示:注意:更新顺序对于 wcf 验证子系统很重要。如果您以错误的顺序更新它,您可能会遇到验证异常。
Yes. If your application is allowed to change files in the application folder - update
*.config
file, by file IO operations or by doing "sectionupdate
/save
/refresh
" . There is straight forward logic in this solution - want to have remote configuration? Get it from remote, update local and have it.Sample: let say you have stored your wcf section's group (
<bindings>
,<behaviors>
.. etc) in the filewcfsections.test.config
(of course any remote source is possible) and want to "overload" conf file configuration. Then configration update/save/refresh code looks like:Note: the updates order is important for wcf validation subsystem. If you update it in wrong order, you can get validation exceptions.