用户可写配置文件的示例?
我的 (C# 4.0) 项目中迫在眉睫的是引入用户配置功能,其中我的同事需要获得配置我们的软件或预运行基础的能力,以便它能够以任何需要的方式履行其职责。每次运行(它们往往是冗长的模拟)都会有自己的配置文件。
总的来说,他们想要定义“产品”,相当复杂的野兽,包括运行时参数、IOC 样式信息(策略模式类似的方式)以及更多的东西。值可以是数字(整数和浮点)、字符串、日期及其列表。
我们知道随着新产品的推出或现有产品的发展,内容会发生变化(例如新的参数名称)。
我看过的选项包括,按(我估计的)语法重量的降序排列:
- XML
- YAML
- JSON一个>
- 一个<一个href="http://martinfowler.com/bliki/DomainSpecificLanguage.html" rel="nofollow">域特定语言?
- 一些特定于应用程序的文本符号
我正在寻找或多或少相似的事物的示例:文件格式、从技术和/或用户角度讨论优缺点。
(我希望在将来的某个时候,我们会考虑为此类练习引入图形前端,但我们需要能够在此之前的某个时间配置执行。)
编辑/更新:我不特别关心从技术角度来看实施的难易程度:我正在寻找我的(非常聪明,但不面向技术的)用户最能够使用的东西来最小化编写相当复杂的配置的难度。
也许“配置”这个词是一个错误的选择 - 如果我们将其称为“模拟定义文件”并考虑到每个用户随着时间的推移会创建许多这样的文件怎么办?
Looming on my (C# 4.0) project horizon is the introduction of a user-configuration feature, wherein my colleagues need to obtain the ability to configure our software or a pre-run basis so that it will perform its duties in whatever way is needed. Every run (they'll tend to be lengthy simulations) will have have its own configuration file.
In the main, they'll want to define "products", fairly complex beasts comprising run-time parameters, IOC-style information (lists of calculation classes required in a Strategy Pattern-like way) and more stuff besides. Values could be numbers (integer and floating-point), strings, dates and lists of these.
We know the content will change (new parameter names, for example) as new products are introduced or existing ones evolve.
Options I've looked at include, in descending order of (my estimate of) syntax-heaviness:
- XML
- YAML
- JSON
- a DomainSpecific Language?
- Some app-specific text notation
I'm looking for examples of more-or-less similar things: file formats, discussions of pros and cons from a technical and/or user perspective.
(I expect that at some time in the future we'll consider introducing a graphic front-end for such exercises, but we'll need to be able to configure executions some time before then.)
EDIT/UPDATE: I'm not particularly concerned about ease of implementation from the technical perspective: I'm looking for something my (very smart, but not technically-oriented) users will best be able to use to minimize the difficulty of writing what may be a fairly complex configuration.
Maybe "configuration" is a bad choice of word - what if we called it "simulation definition file" and considered that each user will create many of these over time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果所有这些都可以用常规的、面向属性的方式来描述,那么听起来 XML 就能满足您的需求。 C# 具有出色的 XML 处理功能,包括内置序列化器和 LINQ,可以节省大量代码实现时间。此外,从架构创建基于表单的 UI 非常简单。
我建议坐下来创建一个伪模式,看看这是否可以处理您的用例,以帮助确定这种方法是否适合您。
例如,看一下由 XML 驱动的众多插件系统之一。我推荐的第一个是 Eclipse。
If all of this can be described in a regular, attribute oriented way, it sounds like XML would meet your needs. C# has fantastic XML handling features including built-in serializers and LINQ that can save a ton of code implementation time. Also, creating a forms based UI from a schema is very straight forward.
I would suggest sitting down and creating a pseudo-schema to see if this would handle your use cases to help decide if this approach would work for you.
For examples, take a look at one of the many plugin systems that are driven by XML. The first one I would recommend is Eclipse.
在C#中,最简单的方法是使用内置类
System.Configuration
,首先您应该使用Visual Studio添加一个配置文件,然后您可以编辑它的属性。这是操作方法In C# easiest way is to use a Built In Class
System.Configuration
,first you should add an Configuration File ,using Visual Studio ,than you can edit it's attributes . Here is a How To