views:

35

answers:

0

Hi,

I'm using MEF and XML serialisation in my application. To put my question simply can i write a static class with a function like this:

public static List<Type> GetImplementations(Type type, AggregateCatalog catalog) {
   ??? (type is an abstract class)
}

The back story:

I use MEF to enable third party pluggins, however i want to be able to serialise these using the built in xml serialisation:

public class Project {
  public List<APlugin> Plugins{get;set;} // APlugin is abstract
}

however because the serialisor doesn't know about the types of the APlugin the xml serialistion fails. Clearly i can seed the serialisor with the types - providing i know what they are at compile time - which i don't due to MEF - hence the above question.

Clearly a work around is just to create a class:

public class APluginFinder {
  [ImportMany]
  APlugin[] plugins;
}

but i wonder if there is a much nicer solution? - eg is it possible to make a generic finder class?