How can I check, that there are exports already defined in container?

Oct 16, 2012 at 7:56 PM

How can I check, that there are exports already defined in container?
Now I use this code:

var declaredTypes = typeof(MefBootstrapper).DeclaringType.GetTypeInfo().Assembly.DefinedTypes.Select(dt => dt.AsType()).ToList();
var parts = new List<Type>(declaredTypes.Count);
using (var container = ContainerConfiguration.CreateContainer())
{
    foreach (var type in declaredTypes)
    {
        object export;
        bool isExportDefined = container.TryGetExport(type, out export);
        if (!isExportDefined)
            parts.Add(type);
    }
}
ContainerConfiguration.WithParts(parts);

But it does not look efficient.