[英].NET ApplicationSettingsBase Should I call Upgrade() every time I load?
We have application settings derived from ApplicationSettingsBase
. 我们有从ApplicationSettingsBase
派生的ApplicationSettingsBase
程序设置。 When we push a new version of our app we need to call: 当我们推送新版本的应用时,我们需要致电:
//
// Summary:
// Updates application settings to reflect a more recent installation of the
// application.
public virtual void Upgrade();
(from the meta-data) (来自元数据)
Now there are some tricky ways to determine if your settings need to be upgraded such as this post which would seem to me to only ever upgrade your settings once. 现在有一些棘手的方法可以确定您的设置是否需要升级,例如这篇文章在我看来只会升级您的设置一次。 Now I could store the current version of my application in the settings and compare whenever I instantiate the settings, if it is different to the current version then I could upgrade. 现在我可以将我的应用程序的当前版本存储在设置中,并在每次实例化设置时进行比较,如果它与当前版本不同,那么我可以升级。
My question is why not just call Upgrade()
every time I instantiate the settings? 我的问题是为什么不在每次实例化设置时调用Upgrade()
? That way i know I will never be out of date. 这样我知道我永远不会过时。
The method described in the linked post does work. 链接帖子中描述的方法确实有效。 I've used that method myself. 我自己也用过那种方法。 When your application version changes the settings will be reset to their defaults and the UpdateRequired
property will be true
. 当您的应用程序版本更改时,设置将重置为其默认值, UpdateRequired
属性将为true
。
So no, you don't have to call Upgrade
every time your app starts. 所以不,每次你的应用程序启动时你都不必调用Upgrade
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.