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
OnDeserializeUnrecognizedElementmethod of theConfigurationSectionclass. 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
Whaaobject, or:for getting a
WhaaChildobject at runtime.