Monday, January 23, 2012

Strongly Typed Configuration Sections

I generally don't like to use strongly typed configuration sections, but I'm working on a project that uses them very heavily and just encountered an annoying issue.

When you have a configuration collection such as shown below, there is no way to access the value of customAttribute in the your strongly typed collection class.

<folderlist customattribute="value">
<add attribute1="value" attribute2="value">
<add attribute1="value" attribute2="value">

The link below shows an example of how this can be resolved, but it is a bit nasty.

One thing to note is that in your class definition, you cannot use the [ConfigurationProperty] attribute on the property exposing the attribute, otherwise the property will not be identified as an unrecognised attribute and so your code will never be hit..

No comments:

Post a Comment