public static ToolPage PageFromType(string id) { List <Type> pagetypes = VType.GetDerivedTypes(typeof(ToolPage), Assembly.GetExecutingAssembly()); foreach (Type pagetype in pagetypes) { ToolPage instance = Activator.CreateInstance(pagetype) as ToolPage; if (instance.PageName == id) { return(instance); } instance.Dispose(); } return(null); }
public static List <Type> GetDerivedTypes(Type baseType, Assembly assembly) { // Get all types from the given assembly Type[] types = assembly.GetTypes(); List <Type> derivedTypes = new List <Type>(); for (int i = 0, count = types.Length; i < count; i++) { Type type = types[i]; if (VType.IsSubclassOf(type, baseType)) { // The current type is derived from the base type, // so add it to the list derivedTypes.Add(type); } } return(derivedTypes); }