使用 XSD 生成的类反序列化 web.config 自定义部分
我在 Web.Config 文件中有一个自定义部分,并通过 configSource 引用另一个 .config 文件。我已使用 XSD 为我的架构生成了 .cs 文件。如何使用我生成的类来反序列化配置。当我尝试使用 .GetSection() 方法加载 configsection 时,它给出了该类应从 ConfigurationSection 实现的错误。由于我使用 xsd 生成了这些类,因此它们不是从 ConfigurationSection 或 ConfigurationElement 继承的。提前致谢!!
I Have a custom section in Web.Config file and referring another .config file through configSource. I have generated .cs file using the XSD for my schema. How to use my generated classes to deserialize the config. When I try to load the configsection using .GetSection() method, it gives me error that the class should implement from ConfigurationSection. Since I have generated the classes using xsd, they were not inherited from ConfigurationSection or ConfigurationElement. Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经实现了 ConfigurationSection 中的类来获取文件名,并使用 XMLSerializer 使用 XSD 工具生成的类进行反序列化。这是示例:
在指定自定义配置时,我无法使用 configSource 属性作为我的属性,因为它是由 ConfigurationManager 保留的。
I have implemented the class from ConfigurationSection to get the file name and using XMLSerializer to Deserialize using the classes generated by XSD tool. Here is sample:
I cannot use the configSource attribute as my property while specifying the custom config, because it is reserved by ConfigurationManager.