0

I use XML for my configuration files and currently I deserialize into objects or lists of objects directly. I also use Managed Extensibility Framework (MEF) to make extensions to our application platform but I haven't found a way to tie the two together.

For instance if I wanted to add a new object to this base class using XMLInclude:

[XmlInclude(typeof(SubObject1))]
[XmlInclude(typeof(SubObject2))]
[XmlInclude(typeof(SubObject3))]
//New XmlInclude Types based on plugins?
[XmlType("SupportedObject")]
public class SupportedObject
{
    public string Name { get; set; }
}

with XML:

<SupportedObjects>
  <SupportedObject xsi:type="SubObject1">
      <Name>MainSub1</Name>
      <SubObject1Param>FooBar</SubObject1Param>
  </SupportedObject>

  <!-- MEF Plugin Object -->
  <SupportedObject xsi:type="MefObject1">
      <Name>MainSub1</Name>
      <MefParam1>something new</MefParam1>
  </SupportedObject>
</SupportedObjects>

The first object would load fine because it is defined using the XmlInclude but how do I define an extension that is compiled in a dll and loaded as a lazy list object with contract to be included as a supported object xmlinclude as well? I'm quite vexed.

Jeremy
  • 9
  • 4
  • Does this answer your question? [How to add XmlInclude attribute dynamically](https://stackoverflow.com/q/2689566/3744182) – dbc Dec 11 '19 at 18:53
  • So the process would be to load the extensions then add the xml include attribute dynamically, then perform the xml deserialization? – Jeremy Dec 11 '19 at 23:18
  • Yes. You would also need to cache the `XmlSerializer` statically as explained in [Memory Leak using StreamReader and XmlSerializer](https://stackoverflow.com/q/23897145/3744182). – dbc Dec 11 '19 at 23:20

0 Answers0