最好能提供软件的设置方式是什么? [英] Best way to provide software settings?

查看:109
本文介绍了最好能提供软件的设置方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#.NET。

在我的软件,我提供的设置对话框,用户可以通过它设置,我想保存到一个文件中的应用程序设置。

In my software I'm providing settings dialog through which user can set the application settings which I want to save to a file.

要求(典型值):

  1. 在我定义的每个类使用这些设置的某些部分。那么,这些应该是全局的所有类。
  2. 当软件启动这些应该被加载。
  3. 在当前不断变​​化的用户设置,并点击保存/应用。当前设置应该改变。

我想知道什么是做到这一点的最好方法是什么?此外,什么是保存这些设置保存到磁盘的最佳方式是什么?我的意思是我应该创建一个设置类对象,并将其序列化到settings.dat或提供类似XML的结构化的文件/ JSON

I am wondering what is the best way to do this? Also, what is the best way to save these settings to disk? I mean should I create a Settings class object and serializing it to 'settings.dat' or provide an structured file like XML/JSON

这是需要的几乎所有其他软件。那么,是不是有什么设计模式呢?

This is required for almost every other software. So, isn't there any design pattern for this?

编辑:

好了,那东西,我不知道。这真好 :)。但说而用户使用他在改变了设置,然后所有正在使用这些全球Properties.Settings.Default其他对象的中间的软件。*应该改变。是否有任何形式的通知机制?有些类型的事件?

Well, thats something that I didn't know. Its nice :). But say while user is using the software in the middle he changes the settings then all the other objects that are using these global Properties.Settings.Default.* should be changed. Is there any kind of notification mechanism? Some kind of event?

推荐答案

随.NET中设置类是非常方便的,我用它我的大多数项目。在有一个问题需要注意的是,应用程序的每个新版本都有自己的设置文件,所以请确保您有SensAble公司违约。每当一个新的EXE分发所有的设置都将消失。

The Settings class that comes with .Net is very handy, and I use it for most of my projects. The one gotcha to watch out for is that every new version of the application gets its own settings file, so make sure you have sensable defaults. All the settings will disappear whenever a new EXE is distributed.

全局状态是非常困难的正确处理,所以我通常通过相关设置的各种对象在其构造函数,或属性。我一般不适用的设置更改这些对象,因为,在许多情况下,这是非常困难的,以对付不断变化的设置智能的对象。相反,我只是用新设置的新对象,因为他们创建的。如果设置需要立即应用,然后我就甩旧的对象,并创建一个新的。这只是取决于该应用程序的细节。

Global state is very hard to deal with correctly, so I usually pass the relevant settings to the various objects in their constructors, or in properties. And I usually don't apply settings changes to those objects, since, in many cases, it's very hard for an object to deal with a changing setting intelligently. Rather, I just use the new settings for the new objects as they are created. If a setting needs to be applied immediately, then I just dump the old object and create a new one. It just depends on the details of the application.

如果你有一个应用设置屏幕上的按钮,然后我会建议重装并保存后,显示所有的值。通过这种方式,显示效果一定要包含实际上正是保存。这可能是重要的,如果任何设置被解析。我有用户输入月份和日期组合成一个特定的领域,他们使用的格式是与预期不同,所以保存的值是不正确的。通过更新应用之后的屏幕,这些类型的错误可以进行明显的。

If you have an Apply button on your settings screen, then I would recommend reloading and displaying all of the values after saving them. This way the display is sure to contain exactly what is actually saved. This could be important if any settings are parsed. I've had users enter a month and day combination into a particular field, and the format they used was different from what was expected, so the value saved was incorrect. By updating the screen after the Apply, these sorts of errors can be made obvious.

我希望这有助于!

这篇关于最好能提供软件的设置方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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