Same Type Exports for Exports

Nov 19, 2009 at 3:14 PM
Edited Nov 19, 2009 at 6:14 PM

I'm looking into a situation where I'd like to provide a recursive model for some Exports on a project.  I know that I can create Exports that are also composed of various parts themselves; however, can those "subparts" be of the same type?  I tried a quick concept before work this morning and got a Reflection-based error (forgot to note which one).

Ultimately, what I wrote was the below using .net 3.5 and MEF beta 2.

 

[Export("initialPart", typeof(IFoo))]
public class MyInitialPart : IFoo
{
    // ... IFoo Implementation Code

    [ImportMany("subPart", typeof(IFoo))]
    public IEnumerable<IFoo> SubParts { get; set; }
}

 

Is it possible to have an Export that also attempts to have Imports of the same type but different contract description/label?

 

Developer
Nov 19, 2009 at 6:08 PM

What you are doing should work I think the error you are suing is with your ImportMany property type. Try changing it to IEnumerable<IFoo>.

Nov 19, 2009 at 6:14 PM

Actually, that was an issue with the code paste.  I did have IEnumerable<IFoo> but it looks like the text area didn't encoded it.  I'll update such.

Nov 20, 2009 at 2:32 PM

After starting a new project to simplify things again I discovered that it was working.  Looking deeper at the project that I was using when I posted this question, I see that I had an old copy of a DLL in my DirectoryCatalog's path.  This old DLL is what was causing my ReflectionTypeLoadException.

Thanks for your help.