如何序列化 System.Configuration.SettingsProperty [英] How to serialize System.Configuration.SettingsProperty
问题描述
我需要通过 WCF 序列化 System.Configuration.SettingsProperty 和 System.Configuration.SettingsPropertyValue 类对象.
使用自己的类是合理的选择.如果需要,您还可以使用 VS 设计器设置.
VS 设计器将属性设置保存在 ApplicationSettingsBase一>类.默认情况下,这些属性被序列化/反序列化为每个用户的 XML 文件.因为 WCF 服务没有用户上下文,所以这将不起作用.您可以使用自定义 SettingsProvider 覆盖此行为这使得将属性保留在您想要的任何位置变得非常容易.只需将 SettingsProvider
属性添加到 VS 生成的 Settings
类:
[SettingsProvider(typeof(CustomSettingsProvider))]内部密封部分类设置{...}
RegistrySettingsProvider就是一个很好的例子.>
我最初阅读您的问题时以为您在询问如何在 WCF 服务中保留设置.我现在看到您想通过 WCF 传递设置.SettingsProvider 类也可用于此目的.
I need to serialize the System.Configuration.SettingsProperty and System.Configuration.SettingsPropertyValue class object through WCF.
Using your own class is reasonable option. You can also use the VS designer settings if you want.
The VS designer keeps property settings in the ApplicationSettingsBase class. By default, these properties are serialized/deserialized into a per user XML file. Because there is no user context for a WCF service, this will not work. You can override this behavior by using a custom SettingsProvider which makes it pretty easy to keep the properties where ever you want. Just add the SettingsProvider
attribute to the VS generated Settings
class:
[SettingsProvider(typeof(CustomSettingsProvider))]
internal sealed partial class Settings {
...
}
A good example of this is the RegistrySettingsProvider.
Edit: My initial read of your question thought you were asking how to persist settings in a WCF service. I see now you want to pass settings through WCF. The SettingsProvider class could also be used for this purpose.
这篇关于如何序列化 System.Configuration.SettingsProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!