private void ExamineAssembly(Assembly assembly) { // Get a list of all the types in the assembly Type[] allTypes = assembly.GetTypes(); foreach (Type type in allTypes) { // Only scan classes that arn't abstract if (type.IsClass && !type.IsAbstract) { // If a class implements the IFactoryProduct interface, // which allows retrieval of the product class key... Type iFactoryProduct = type.GetInterface("IFactoryProduct"); if (iFactoryProduct != null) { // Create a temporary instance of that class... object inst = assembly.CreateInstance(type.FullName, true, BindingFlags.CreateInstance, null, null, null, null); if (inst != null) { // And generate the product classes key IFactoryProduct keyDesc = (IFactoryProduct)inst; object key = keyDesc.GetFactoryKey(); inst = null; // Determine whether the product class implements // one or more of the neccesary product interfaces // and add mappings for each one thats implemented Type tProduct = typeof(TProduct); Type prodInterface = type.GetInterface(tProduct.ToString()); if (prodInterface != null) { registry.Add(key, new Pair <Assembly, Type>(assembly, type)); } } } } } }