在.NET中多设置文件 [英] Multiple settings files in .NET

查看:185
本文介绍了在.NET中多设置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用My.Settings / Properties.Settings存储各种用户设置。许多这样的设置必然要以各种形式控制。

I'm currently using My.Settings/Properties.Settings to store various user settings. Many of these settings are bound to controls in various Forms.

不过,我希望有一个更大程度的控制 - 特别是我希望能够重新加载或保存设置的特定群体。使用内置Settings.settings文件,我只能处理这些设置作为一个组。

However I want a greater degree of control - specifically I would like to be able reload or save specific groups of settings. Using the in-built Settings.settings file, I can only handle these settings as a single group.

我知道,我可以创造额外的设置文件,<一个href="http://www.dondraper.com/2011/01/easily-save-and-retrieve-application-and-user-settings-in-vb-net-or-c-apps/"相对=nofollow>这篇文章(摘要部分)认为,如果Settings.settings不是present,该应用程序将在项目的根其他.settings文件,但这似乎并没有对于我的情况下(除非我做错了什么):

I know that I can create additional settings files, and this article (Summary section) suggests that if Settings.settings is not present, the application will look for other .settings files in the project root, but this doesn't seem to be the case for me (unless I am doing something wrong):

他们提供了巨大的力量和灵活性。例如,您可以添加   自定义设置文件到您的项目设置管理   在不同的组。这使您可以保存设置为一组或   装在不同的文件值,可以节约节约型和子集   时间。

They offer tremendous power and flexibility. For example, you can add customized settings files to your project for management of settings in different groups. This allows you to save settings for a group or subset of values in separate files which can save saving and loading time.

我在建设自己的设置类,做这一切我自己的观点,但是这将是一种耻辱 - 在内置功能适合我 - 提供我可以有多个设置文件

I'm on the point of building my own Settings class and doing it all myself, but it would be a shame - the in-built functionality suits me well - providing I can have multiple settings files.

更新本文建议您可以添加额外的设置文件和对面属性文件夹拖动它们。不幸的是,我目前的项目是在VB.Net这种行为似乎并没有被复制。

UPDATE: This article suggests that you can add additional settings files and drag them across to the Properties folder. Unfortunately, my current project is in VB.Net and this behaviour does not appear to be replicated.

推荐答案

该解决方案,它的出现,是根据需要添加任意数量的.settings文件。在属性为每个添加的客户工具名称 - 在我的情况下,我选择了我,以配合内置Setting.settings。

The solution, it appears, is to add as many additional .settings files as needed. In the properties for each, add in a Customer Tool Name - in my case I chose 'My' to match the in-built Setting.settings.

此后,您可以访问各自设置独立的文件,内容如下:

Thereafter you can access each settings file independently, as follows:

My.Options1.Default.Foo = "bar"
My.Options2.Default.Foo = "bar"

My.Options1.Default.Save()
My.Options2.Default.Reload()

.DEFAULT 的是一个小麻烦,但除此之外,这似乎工作,我所希望的。

The .default is a minor annoyance, but other than that, this appears to work as I hoped.

这篇关于在.NET中多设置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆