动态 ConfigurationSection 是否可以以简单的方式实现?
在 .NET 1.0 中,IConfigurationSectionHandler 提供了一个干净的单一方法接口来实现配置处理程序。
在 .NET 2 中,ConfigurationSection 出现了,它是一个复杂性和静态类型执行的笨重野兽,挥舞着横幅宣称“如果使用 IConfigurationSectionHandler,将会发生未知的邪恶!”。
作为一个叛逆者,我试图将插件架构硬塞到像 .NET 2 这样古老的静态框架中,我想要一个动态配置部分。没有什么静态的,只是一个漂亮的 XML 节点树或嵌套的键/值对。插件无需定义脆弱的序列化代码即可访问的东西。
就像 XML 最初的用途一样,在它成为脆弱的 catch-22 web.config 恐怖和痛苦的样板序列化树的预兆之前。
请问有什么方法可以获取 XMLElement 实例或 XMLReader 吗?
In .NET 1.0, IConfigurationSectionHandler offered a clean, single method interface to implementing a configuration handler.
In .NET 2, ConfigurationSection came along, a great lumbering beast of complexity and static type enforcement, waving a banner proclaiming "Unknown evils will happen if you use IConfigurationSectionHandler!".
Being the rebel that I am, trying to shoehorn a plugin architecture into a ancient, static framework like .NET 2, I want a dynamic configuration section. Nothing static, just a nice tree of XML nodes or nested key/value pairs. Something that plugins can access without defining fragile serialization code.
Like XML was originally intended for, before it became the harbinger of fragile catch-22 web.config horrors and painful boilerplate serialization trees.
Is there any way I can just get an XMLElement instance, or XMLReader, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑到这篇文章的年龄,您可能已经自己找到了相同的答案...
您可以实现一个仅需要重写受保护方法
DeserializeSection()
的ConfigurationSection
>。您的自定义配置部分不需要遵循基于属性的属性模式,这是 .NET 2 配置的规范。DeserializeSection
接受XmlReader
作为其唯一参数。您可以使用该XmlReader
从您的部分中解析出 XML,并以您选择的任何方式公开该数据。Considering the age of this post, you may have already found this same answer on your own...
You can implement a
ConfigurationSection
that only needs to override the protected methodDeserializeSection()
. Your custom config section does not need to follow the attribute based property pattern that is the norm for .NET 2 configuration.DeserializeSection
accepts anXmlReader
as its only parameter. You can use thatXmlReader
to parse out the XML from within your section and expose that data any way you choose.