Lets say I have the following configuration section....
<yak>
<whaa hello="world" />
</yak>
<yak>
<whaa hello="world" blot="1" />
</yak>
Because the second <whaa>
element has the extra attribute on it I want to map it to a sub type of the the type that's mapped to the first <whaa>
element.
So how do I get polymorphic binding?
Here's one approach by using a programmatic solution which overrides the
OnDeserializeUnrecognizedElement
method of theConfigurationSection
class. The base and child configuration element classes:The configuration section class:
The sample usage:
And the configuration markup:
You may use now either:
for getting a
Whaa
object, or:for getting a
WhaaChild
object at runtime.