Changeset 2234
- Timestamp:
- 08/05/09 10:02:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/DiscoveryService.cs
r1189 r2234 47 47 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); 48 48 List<Type> types = new List<Type>(); 49 foreach (Assembly asm in assemblies) {49 foreach (Assembly asm in assemblies) { 50 50 Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) { 51 51 types.Add(t); … … 63 63 Type[] types = GetTypes(typeof(T)); 64 64 List<T> instances = new List<T>(); 65 foreach (Type t in types) {66 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {65 foreach (Type t in types) { 66 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) { 67 67 instances.Add((T)Activator.CreateInstance(t)); 68 } 69 } 70 return instances.ToArray(); 71 } 72 73 /// <summary> 74 /// Creates an instance of all types that are subtypes or the same type of the specified type 75 /// </summary> 76 /// <typeparam name="type">Most general type.</typeparam> 77 /// <returns>The created instances as array.</returns> 78 public object[] GetInstances(Type type) { 79 Type[] types = GetTypes(type); 80 List<object> instances = new List<object>(); 81 foreach (Type t in types) { 82 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) { 83 instances.Add(Activator.CreateInstance(t)); 68 84 } 69 85 } … … 81 97 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); 82 98 List<Type> types = new List<Type>(); 83 foreach (Assembly asm in assemblies) {84 if (plugin.Assemblies.Contains(asm.Location)) {99 foreach (Assembly asm in assemblies) { 100 if (plugin.Assemblies.Contains(asm.Location)) { 85 101 Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) { 86 102 types.Add(t); … … 101 117 Type[] types = GetTypes(typeof(T), assembly); 102 118 List<T> instances = new List<T>(); 103 foreach (Type t in types) {104 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {119 foreach (Type t in types) { 120 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) { 105 121 instances.Add((T)Activator.CreateInstance(t)); 106 122 } … … 117 133 internal Type[] GetTypes(Type type, Assembly assembly) { 118 134 List<Type> types = new List<Type>(); 119 foreach (Type t in assembly.GetTypes()) {120 if (type.IsAssignableFrom(t)) {135 foreach (Type t in assembly.GetTypes()) { 136 if (type.IsAssignableFrom(t)) { 121 137 types.Add(t); 122 138 } … … 131 147 /// <returns>The found plugin or <c>null</c>.</returns> 132 148 public PluginInfo GetDeclaringPlugin(Type type) { 133 foreach (PluginInfo info in PluginManager.Manager.LoadedPlugins) {134 if (info.Assemblies.Contains(type.Assembly.Location)) return info;149 foreach (PluginInfo info in PluginManager.Manager.LoadedPlugins) { 150 if (info.Assemblies.Contains(type.Assembly.Location)) return info; 135 151 } 136 152 return null;
Note: See TracChangeset
for help on using the changeset viewer.