DirectoryCatalog - finding files in subdirectories

Feb 26, 2010 at 9:43 PM

Pretty new to MEF.  We're migrating our product from System.AddIn to MEF.  I'm loving the simplicity of MEF. 

One question/observation.  System.AddIn's discovery process allowed each AddIn to be in its own subdirectory.  This is nice if you have many addins that each have many files.

As such, I was looking for this in DirectoryCatalog.  AFAIK you can't do this with just the search pattern.  I added a SearchOption parameter to the constructor, and altered the DirectoryCatalog.GetFiles code to pass that along to Directory.GetFiles.

Is there already a good way to do this that I'm missing, or is this useful enough to be added in a future release?

Thanks,

Jason

Feb 26, 2010 at 11:21 PM

AggregateCatalog.  You can use it to roll up multiple catalogs - something like this -

AggregateCatalog agcatalog = new AggregateCatalog();
foreach (var plugindir in Directory.GetDirectories(pluginDirectory))
{
       DirectoryCatalog dcat = new DirectoryCatalog(plugindir);
       agcatalog.Catalogs.Add(dcat);
                
 }