自定义在C#以下的app.config? [英] Customize the following app.config in C#?

查看:151
本文介绍了自定义在C#以下的app.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要解析通过一个通用的解析器含头几个逗号分隔的文件。标头蜂拥而至数量,我需要提供选择几头说事的能力。

I have to parse several comma-separated files containing headers via a generic parser. The headers come in great number, and I need to provide the ability to choose the few headers that matter.

这是实现我一般每个文件类型的具体解析器必须覆盖一个在线(IDictionary的|字符串,字符串|线)等等方法。该行映射头值在该行相应的数据。

The concrete parsers that implement my generic one for each file type have to override an onLine(IDictionary|string,string| line) method among others. This line maps header value to corresponding data in the line.

我的问题:我在的app.config此刻用逗号分隔的列表。那问题是我具体的解析器将不得不使用实际的标头值作为键。我希望能够引进常数,所以没有重建是万一头必要的修改

My problem : I use a comma-separated list in my app.config at the moment. The problem of that is that my concrete parsers will have to use actual header values as keys. I'd like to be able to introduce constants, so that no rebuild is necessary in case a header changes.

在此刻我的app.config看起来像这样:

at the moment my app.config looks like this :

  <configSections>
    ...
    <section name="headers" type="System.Configuration.NameValueSectionHandler" />
    ...
  </configSections>
  ...
  <headers>
    ...
    <add key="file1" value="actualheader1,actualheader2,actualheader3" />
    <add key="file2" value="actualheader4,actualheader5,actualheader6" />
    <add key="file3" value="actualheader7,actualheader8,actualheader9" />
    ...
  </headers>
  ...



我需要在什么条件标签一样的东西(没有任何要求,钥匙,价值,只是想展现逻辑,我以后):

I would need something like (no requirements in terms of what is tag, key, value, just trying to show the logic I am after):

  <configSections>
    ...
    <section name="headers" type="?" />
    ...
  </configSections>
  ...
  <headers>
    ...
    <file1>
      <add key="headerconstant1" value="actualheader1" />
      <add key="headerconstant2" value="actualheader2" />
      <add key="headerconstant3" value="actualheader3" />
    </file1>
    <file2>
      <add key="headerconstant4" value="actualheader4" />
      <add key="headerconstant5" value="actualheader5" />
      <add key="headerconstant6" value="actualheader6" />
    </file2>
    <file3>
      <add key="headerconstant7" value="actualheader7" />
      <add key="headerconstant8" value="actualheader8" />
      <add key="headerconstant9" value="actualheader9" />
    </file3>
    ...
  </headers>
  ...



第二个选项将使实际标头值的变化找到文件,而不影响的代码。

The second option would enable changes in the actual header value to find in files without impacting the code.

我怎样才能做到这一点?我没有任何的quickfix已经实现?

How can I do this ? I there any quickfix already implemented ?

推荐答案

如果你想与配置做到这一点,但不希望的学习曲线手编码了你的配置部分检查 http://csd.codeplex.com/ 以一个Visual Studio插件。很干净,很容易理解。

If you want to do it with the config but don't want the learning curve of hand coding up the your config section check out http://csd.codeplex.com/ for a visual studio addin. Very clean and easy to understand.

这篇关于自定义在C#以下的app.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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