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

Categories .NET, Development, Unit testing

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

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

foreach (Assembly asm in assemblies)
{
        IEnumerable<Type> 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.

1 thought on “Get all the types contained in all the assemblies loaded, filtered by namespace

  1. Top notch post GridPulse : Get all the types contained in all the assemblies loaded, filtered by namespace | Bogdan Costea you’ve definitely inspired all of us Moreover have you read Tunisia notable news. Cheers ! Rob Rasner Comedian

Leave a Reply

Your email address will not be published. Required fields are marked *