using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
namespace MefPlugin
{
class MefPlugin<T>
{
public string Path { get; protected set; }
public CompositionContainer Container { get; protected set; }
[ImportMany()]
protected IEnumerable<T> Items;
public MefPlugin(string PluginDirectry)
{
Path = PluginDirectry;
var DC = new DirectoryCatalog(PluginDirectry);
//var AC = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
var Catalog = new AggregateCatalog(DC);//,AC);
Container = new CompositionContainer(Catalog);
}
public IEnumerable<T> GetPlugins(){
Items = Container.GetExportedValues<T>();
return Items;
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5UZXh0OwoKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsLkNvbXBvc2l0aW9uOwp1c2luZyBTeXN0ZW0uQ29tcG9uZW50TW9kZWwuQ29tcG9zaXRpb24uSG9zdGluZzsKCm5hbWVzcGFjZSBNZWZQbHVnaW4KewogICAgY2xhc3MgTWVmUGx1Z2luPFQ+CiAgICB7CiAgICAgICAgcHVibGljIHN0cmluZyBQYXRoIHsgZ2V0OyBwcm90ZWN0ZWQgc2V0OyB9CiAgICAgICAgcHVibGljIENvbXBvc2l0aW9uQ29udGFpbmVyIENvbnRhaW5lciB7IGdldDsgcHJvdGVjdGVkIHNldDsgfQogICAgICAgIFtJbXBvcnRNYW55KCldCiAgICAgICAgcHJvdGVjdGVkIElFbnVtZXJhYmxlPFQ+IEl0ZW1zOwoKICAgICAgICBwdWJsaWMgTWVmUGx1Z2luKHN0cmluZyBQbHVnaW5EaXJlY3RyeSkKICAgICAgICB7CiAgICAgICAgICAgIFBhdGggPSBQbHVnaW5EaXJlY3RyeTsKCiAgICAgICAgICAgIHZhciBEQyA9IG5ldyBEaXJlY3RvcnlDYXRhb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