.NET ApplicationSettingsBase 我应该在每次加载时调用 Upgrade() 吗?
我们有从 ApplicationSettingsBase
派生的应用程序设置。当我们推送应用程序的新版本时,我们需要调用:(
//
// Summary:
// Updates application settings to reflect a more recent installation of the
// application.
public virtual void Upgrade();
来自元数据)
现在有一些棘手的方法可以确定您的设置是否需要升级,例如 这篇文章 这似乎我只会升级你的设置一次。现在,我可以将应用程序的当前版本存储在设置中,并在实例化设置时进行比较,如果它与当前版本不同,那么我可以升级。
我的问题是为什么不在每次实例化设置时调用 Upgrade()
?这样我就知道我永远不会过时。
We have application settings derived from 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? That way i know I will never be out of date.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接帖子中描述的方法确实有效。我自己也用过这个方法。当您的应用程序版本更改时,设置将重置为默认值,并且
UpdateRequired
属性将为true
。因此,您不必在每次应用启动时都调用
Upgrade
。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 betrue
.So no, you don't have to call
Upgrade
every time your app starts.