Pregunta

What would be the best way to store a tree like the one below in app.config and how would I deserialize this information from it?

Tree
|-node1-
|       |-name - value
|       |-name - value
|       | ......
|-node2-
|       |-name - value
|       |-name - value
|       | ......
|-node3-
|       |-name - value
|       |-name - value
|       | ......

I can convert that tree to xml if that helps.

Thanks for any assistance in advance.

¿Fue útil?

Solución

Use a custom configuration section. For one way to do this, see Configuration Section Designer. You can do it manually, but you might like to play with CSD and see the code it generates.

Otros consejos

You can extend .config with your own types. These can be elements containing other elements and attributes. This area does seem to be poorly documented but there are examples out there.

Start with the System.Configuration.ConfigurationElement class.

You can use and xml based document inside your app with .config extension( like NLog.config , ... ) and use a custom data provider to read the xml data and convert they to tree-like ds.

<Nodes>
    <Node Name="Node1" Value="Value1">
       <Node Name="Node1.1" Value="Value1.2">
       </Node>

       <Node Name="Node1.2" Value="Value1.2">
       </Node>
    </Node>

    <Node Name="Node2" Value="Value2">
    </Node>
</Nodes>

or you can use a custom config section

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top