gpt4 book ai didi

c# - 在 C# 中自定义以下 app.config?

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:27 24 4
gpt4 key购买 nike

我必须通过通用解析器解析几个包含 header 的逗号分隔文件。 header 数量很多,我需要提供选择重要 header 的能力。

为每种文件类型实现我的通用解析器的具体解析器必须重写 onLine(IDictionary|string,string| line) 方法等。此行将 header 值映射到行中的相应数据。

我的问题:目前我在 app.config 中使用逗号分隔的列表。问题是我的具体解析器必须使用实际的 header 值作为键。我希望能够引入常量,以便在 header 更改时无需重建。

目前我的 app.config 看起来像这样:

  <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>
...

我需要类似的东西(对什么是标签、键、值没有要求,只是想展示我所追求的逻辑):

  <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>
...

第二个选项将允许在不影响代码的情况下更改实际 header 值以在文件中查找。

我该怎么做?我有任何已经实现的 quickfix 吗?

最佳答案

如果您想使用配置来完成,但又不想学习手动编码,请查看您的配置部分 http://csd.codeplex.com/对于 Visual Studio 插件。非常简洁且易于理解。

关于c# - 在 C# 中自定义以下 app.config?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10354653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com