I have a custom configuration section registered in app / web.config, call it MySection . I have an ElementCollection element inside a section called MyElements . Inside the collection of elements, I want to have elements that are represented by different classes. The idea is that these are similar classes with some common properties and some instance-specific ones.
Here is an example xml configuration:
<MySection> <MyElements> <Element1 name="someProp1" value="someValue" /> <Element2 name="someProp2" format="{0}{1}" /> </MyElements> </MySection>
In my simple example, all elements must have a 'name' property, some will also have a 'value' property, and another will have a 'format' property. Here, I want Element1 and Element2 appear in the .NET runtime as two different classes that share a common base class that defines the name property.
As far as I fit into the .NET configuration, I got the impression that the collection of elements (for example, "MyElements" here) should contain homogeneous elements (of only one type). So, is it possible to achieve what I want - to make it contain elements of different classes. The idea is to avoid collecting multiple elements for different types of elements, and not to write all duplicate properties for each custom implementation of ConfigurationElement .
source share