I've been playing around with importing/exporting custom delegates and found a problem. I define a custom delegate and have a class that exports both the custom delegate and an equivalent Func:
public delegate int CustomDelegate(double a);
public class DelegateExporter
public Func<double, int> MyFunc = a => 1;
public CustomDelegate MyCustomDelegate = a => 2;
Now an [Import(typeof(CustomDelegate))] fails with an error:
More than one exports were found that match the constraint '((exportDefinition.ContractName = "System.Int32(System.Double)") && (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") && "System.Int32(System.Double)".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.
Clearly I can add different contract names to my exports to distinguish them. Other than that, is there any other way to distinguish the two exports, or is this just a limitation of MEF?
In fact, I've just just tried modifying the above sample to have
public delegate int CustomDelegate1(double a);
public delegate int CustomDelegate2(double a);
This also fails. This seems like a serious limitation to using delegates within MEF, or am I missing something?