0

I have classes coded to parse configuration from a custom app.config using .NET system.configuration library.

It parses this:

<operations>
    <add type="heres_a_type" parameters="parameter1, parameter2"/>
</operations>

I would like to continue to support the above type of configuration, but also support something like this:

<operations>
    <add type="heres_a_type">
        <parameters>param1, param2</parameters>
    </add>
</operations>

Or maybe something like this:

<operations>
    <add type="heres_a_type">
        <parameters>
            <add name="param1" value="param1"/>
        </parameters>
    </add>
</operations>

For when parameters are something more complex, or for readability purposes. I want to support both, so that configuration can be terse most of the time, and expanded out when necessary.

Is there a way to do this with System.Configuration?

I tried adding Type and Parameters a second time as Elements instead of attributes, and making both sets optional, but System.Configuration doesn't like me defining Type and Parameters twice (makes sense).

tigerbyte
  • 107
  • 8
  • At this point, why not just use an XPath query over XML. I think it would be easier than trying to do this, which the configuration library was clearly not meant to do. – Jeremy Jan 23 '15 at 17:09
  • Not sure how xpath would solve my problem here. The xml above is from my app.config. What exactly are you saying I should change to an xpath query? – tigerbyte Jan 23 '15 at 17:19
  • I'm saying the configuration library does not support what you are trying to do, so just treat the config file like the XML document that it is, and change your code to find your data using an XPath query, which gives you the flexibility to read and find whatever nodes in whatever structure you want. – Jeremy Jan 23 '15 at 17:22
  • Yeah, that would work. I don't think I need the ability to represent the data multiple ways badly enough that I want to go down that road, though. If I can't represent the data multiple ways with the configuration library then I'll just pick one way to represent the data and that'll be the only way. – tigerbyte Jan 23 '15 at 17:27

0 Answers0