With the release of .NET4 has anyone ever created a dynamic web.config element that will just let you type anything you want into the config and then you can access it all off a dynamic object?
The amount of work that goes into creating custom config sections is just over the top for seemingly no reason. This has lead me to wonder if someone has replaced the song and dance of easily needing to create 5+ classes to roll a new config section each and every time.
(Note, when I say free form I would obviously expect it to conform to a valid xml element)
If you just want to access the
appSettingssection of the configuration file, you can inherit from theDynamicObjectclass and override theTryGetMembermethod:Then, assuming this is your
app.configfile:… the ‘FavoriteNumber’ setting could be accessed like so:
Note that attempting to access a key that is undefined results in a
RuntimeBinderExceptionbeing thrown. You could prevent this by changing the overriddenTryGetMemberto always returntrue, in which case undefined properties will simply returnnull.