.NET ApplicationSettingsBase 我应该在每次加载时调用 Upgrade() 吗?

发布于 2024-09-14 11:03:18 字数 618 浏览 7 评论 0原文

我们有从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2024-09-21 11:03:19

链接帖子中描述的方法确实有效。我自己也用过这个方法。当您的应用程序版本更改时,设置将重置为默认值,并且 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 be true.

So no, you don't have to call Upgrade every time your app starts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文