I am seeing simple examples regarding custom configuration in .NET. My case is a bit more complex, with nested nodes.
I’d like to be able to read this from the configuration file:
<environments> <environment name='live' url='http://www.live.com'> <server name='a' IP='192.168.1.10'></server> <server name='b' IP='192.168.1.20'></server> <server name='c' IP='192.168.1.30'></server> </environment> <environment name='dev' url='http://www.dev.com'> <server name='a' IP='192.168.1.10'></server> <server name='c' IP='192.168.1.30'></server> </environment> <environment name='test' url='http://www.test.com'> <server name='b' IP='192.168.1.20'></server> <server name='d' IP='192.168.1.40'></server> </environment></environments>
If anyone could provide some code for that, I’d appreciate it.
Thanks!
You can read this by implementing custom configuration classes inheriting from the ConfigurationElement class.
Here is an example of the ‘server’ element:
The environment element is actually a collection and could be implemented like this: