- Timestamp:
- 01/19/10 13:40:52 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationManager.cs
r2594 r2642 157 157 /// <returns>Enumerable of the created instances.</returns> 158 158 internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class { 159 return from t in GetTypes(typeof(T), plugin )159 return from t in GetTypes(typeof(T), plugin, true) 160 160 select (T)Activator.CreateInstance(t); 161 161 } … … 167 167 /// <returns>Enumerable of the created instances.</returns> 168 168 private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class { 169 return from t in GetTypes(typeof(T), asm )169 return from t in GetTypes(typeof(T), asm, true) 170 170 select (T)Activator.CreateInstance(t); 171 171 } … … 186 186 /// <returns>Enumerable of the created instances.</returns> 187 187 internal static IEnumerable<object> GetInstances(Type type) { 188 return from t in GetTypes(type )188 return from t in GetTypes(type, true) 189 189 select Activator.CreateInstance(t); 190 190 } … … 194 194 /// </summary> 195 195 /// <param name="type">Most general type for which to find matching types.</param> 196 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 196 197 /// <returns>Enumerable of the discovered types.</returns> 197 internal static IEnumerable<Type> GetTypes(Type type ) {198 internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable) { 198 199 return from asm in AppDomain.CurrentDomain.GetAssemblies() 199 from t in GetTypes(type, asm )200 from t in GetTypes(type, asm, onlyInstantiable) 200 201 select t; 201 202 } … … 207 208 /// <param name="type">Most general type for which to find matching types.</param> 208 209 /// <param name="plugin">The plugin the subtypes must be part of.</param> 210 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 209 211 /// <returns>Enumerable of the discovered types.</returns> 210 internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription ) {212 internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable) { 211 213 PluginDescription pluginDesc = (PluginDescription)pluginDescription; 212 214 return from asm in AppDomain.CurrentDomain.GetAssemblies() 213 where !string.IsNullOrEmpty(asm.Location ) &&215 where !string.IsNullOrEmpty(asm.Location) && 214 216 pluginDesc.Assemblies.Any(asmPath => Path.GetFullPath(asmPath) == Path.GetFullPath(asm.Location)) 215 from t in GetTypes(type, asm )217 from t in GetTypes(type, asm, onlyInstantiable) 216 218 select t; 217 219 } … … 222 224 /// <param name="type">Most general type we want to find.</param> 223 225 /// <param name="assembly">Assembly that should be searched for types.</param> 226 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 224 227 /// <returns>Enumerable of the discovered types.</returns> 225 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly) { 226 return GetTypes(type, assembly, false); 227 } 228 229 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool includeNotInstantiableTypes) { 228 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) { 230 229 return from t in assembly.GetTypes() 231 230 where type.IsAssignableFrom(t) 232 where includeNotInstantiableTypes || (type.IsAssignableFrom(t) &&!t.IsAbstract && !t.IsInterface && !t.HasElementType)231 where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType) 233 232 select t; 234 233 } … … 253 252 #region IApplicationManager Members 254 253 255 IEnumerable<T> IApplicationManager.GetInstances<T>(IPluginDescription plugin) {256 return GetInstances<T>(plugin);257 }258 259 254 IEnumerable<T> IApplicationManager.GetInstances<T>() { 260 255 return GetInstances<T>(); … … 266 261 267 262 IEnumerable<Type> IApplicationManager.GetTypes(Type type) { 268 return GetTypes(type); 263 return GetTypes(type, true); 264 } 265 266 IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable) { 267 return GetTypes(type, onlyInstantiable); 269 268 } 270 269 271 270 IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin) { 272 return GetTypes(type, plugin); 273 } 271 return GetTypes(type, plugin, true); 272 } 273 274 IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) { 275 return GetTypes(type, plugin, onlyInstantiable); 276 } 277 274 278 275 279 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.