GridPulse

as stimulating as black coffee and just as hard to sleep after.

Get all the types contained in all the assemblies loaded, filtered by namespace

leave a comment

This quick snippet will give you all the types declared in all the assemblies loaded, filtered by namespace.

List types = new List();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

foreach (Assembly asm in assemblies)
{
        IEnumerable asmTypes = from t in asm.GetTypes()
              where t.IsClass
                && (t.Namespace != null && t.Namespace.StartsWith(targetNamespace))
              select t;
        types.AddRange(asmTypes);
}

I actually got to this point because of the way NUnit wraps an assembly in another AppDomain.

The snippet need Linq so it’s for 3.5 or newer.

Written by Bogdan

October 29th, 2009 at 9:05 am

Leave a Reply