How to serialize System.Configuration.SettingsProperty

醉酒当歌 提交于 2019-12-13 19:19:06

问题


I need to serialize the System.Configuration.SettingsProperty and System.Configuration.SettingsPropertyValue class object through WCF.


回答1:


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.




回答2:


I guess you're asking because you can't return a list of SettingProperty. I would create a serializable class myself and load the properties there.



来源:https://stackoverflow.com/questions/170825/how-to-serialize-system-configuration-settingsproperty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!