namespace TACO { using System; using System.Collections; using System.Reflection; public abstract class PartManager { private Hashtable mParts = new Hashtable(); protected PartManager(Type parentType) { Type[] types = parentType.Assembly.GetTypes(); foreach (Type type in types) { if (type.IsSubclassOf(parentType) && !type.IsAbstract) { RegisterPart(type); } } } public abstract string Name { get; } private void RegisterPart(Type type) { Console.WriteLine("Registering {0}", type); mParts[type.FullName] = type; } public Part CreatePart(string name, string id) { Type type = mParts[name] as Type; if (type == null) { Console.WriteLine("{0} was not found!", name); /* TODO: Throw exception */ return null; } return Activator.CreateInstance(type, new object[]{id}) as Part; } public Hashtable Parts { get { return mParts; } } } }