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.
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.
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.
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.
How can I do this ? I there any quickfix already implemented ?
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.