当存储配置信息 [英] Where to store configuration information

查看:241
本文介绍了当存储配置信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我从C重建到C#控制台应用程序。此应用程序必须能够支持存储就像从一个命令行和参数,从一个文件中的参数信息的传统方法(称为系统参数)自定义每个运行。该系统参数文件是纯文本用一个简单的键:值结构

I have a console application that I am rebuilding from C to C#. This application has to be able to support the legacy method of storing information like parameters from a command-line and parameters from a file (called the system parameters) that customize each run. The system parameters file is in plain-text with a simple key : value structure.

  • 我要结合这些不同的参数到一个单一的配置对象?
  • 我怎么会叫这个配置对象从code存储参数?
  • 我怎么会叫从code检索参数此配置对象?
    • 如果这个对象被强类型的?
    • Should I combine these different parameters into a single Configuration object?
    • How would I call this configuration object from the code to store parameters?
    • How would I call this configuration object from the code to retrieve parameters?
      • Should this object be strongly-typed?

      我有一种感觉,它应该是一个单一的,强类型的对象,它应该是从资源库中检索一个静态的检索方法的实例化的对象,但是我真的希望这个方法的验证。

      I have a feeling that it should be a single, strongly-typed object and that it should be an instantiated object that is retrieved from a repository with a static retrieval method however I really want validation of this method.

      在此先感谢

      推荐答案

      我喜欢使用的 设置 。这些可以通过创建使用添加新文件对话框的设置文件,或通过添加从项目属性默认设置文件自动生成。每个设置可以是用户还是应用范围,它控制用户是否可以改变他们或他们被限制在各自的默认值。他们很容易保存在保存()方法,并自动加载到静态默认属性。

      I like using Settings. These can be generated automatically either by creating a Settings File using the Add New File dialog box, or by adding a default Settings File from Project Properties. Each setting may be in User or Application scope, which controls whether or not the user can change them or they are restricted to their default values. They are easily saved with the Save() method and loaded automatically into the static Default property.

      此类似乎是应用程序或基于用户的设置。我在寻找每次运行的设置。你仍建议在这种情况下使用这个类呢? - x97mdr

      This class seems to be for application or user-based settings. I'm looking for per-run settings. Would you still recommend using this class in that case? – x97mdr

      是的。如果您有用户/基于应用程序设置和每个运行的设置,你应该使用两个不同的类 - 正常(保存)的设置和每个运行的设置。只要你不保存每次运行的设置,你应该是安全的,并设置仍然很容易使用。这些都是静态设置虽然。如果同一个应用程序运行需要多个实例 - 这是错误的做法

      Yes. If you have both user/application based settings and per-run settings you should use two different classes - the normal (saved) settings and the per-run settings. As long as you don't save the per-run settings, you should be safe and settings are still quite easy to use. These are static settings though. If the same application run needs several instances - this is the wrong approach.

      这篇关于当存储配置信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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