I thought this would be easy, but after scanning many pages Google hasn't come to my aid.
I have the following in a test method.
var tCatalog = new TypeCatalog(typeof (ISystemIndex));
var aCatalog = new AssemblyCatalog(typeof (ISystemIndex).Assembly);
tCatalog.Parts
comes up empty, while aCatalog.Parts.Count
is 3 (one of them comes from a class decorated with [Export(typeof(ISystemIndex))]
, the other two from classes inheriting from a base w/ Export defined)
What am I doing wrong? Do I need to initialize the TypeCatalog
in some way?
The problem I'm trying to solve is to create a catalog with a subset of the exportable classes in my assembly.
Thanks in advance.
You're trying to create a TypeCatalog
for the interface definition, which is not exported, as there is no [Export]
attribute decorating the ISystemIndex
interface.
If you had a class such as
[Export(typeof(ISystemIndex))]
public class MySystemIndex : ISystemIndex
{
}
and you would create a type catalog
var tCatalog = new TypeCatalog(typeof(MySystemIndex));
then you would have seen it in tCatalog.Parts
.
EDIT
If you want to have a catalog filtered by a certain criteria (e.g. in your case, exports only), check out MEF's documentation about Filtering Catalogs