Changeset 2642
- Timestamp:
- 01/19/10 13:40:52 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.PluginInfrastructure
- Files:
-
- 2 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> -
trunk/sources/HeuristicLab.PluginInfrastructure/Interfaces/IApplicationManager.cs
r2592 r2642 35 35 /// </summary> 36 36 IEnumerable<IPluginDescription> Plugins { get; } 37 37 38 /// <summary> 38 39 /// Gets all discovered applications. … … 40 41 IEnumerable<IApplicationDescription> Applications { get; } 41 42 42 /// <summary>43 /// Discovers and creates instances of <typeparamref name="T"/> and all types implementing or inheriting <typeparamref name="T"/> (directly and indirectly) declared in any assembly of <paramref name="plugin"/>.44 /// </summary>45 /// <typeparam name="T">The type or super-type to discover.</typeparam>46 /// <param name="plugin">The declaring plugin.</param>47 /// <returns>An enumerable of instances of the discovered types.</returns>48 IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class;49 43 /// <summary> 50 44 /// Discovers and creates instances of <typeparamref name="T"/> and all types implementing or inheriting <typeparamref name="T"/> (directly and indirectly). … … 67 61 /// <returns>An enumerable of discovered types.</returns> 68 62 IEnumerable<Type> GetTypes(Type type); 63 64 /// <summary> 65 /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly). 66 /// </summary> 67 /// <param name="type">The type to discover.</param> 68 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 69 /// <returns>An enumerable of discovered types.</returns> 70 IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable); 71 69 72 /// <summary> 70 73 /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>. … … 74 77 /// <returns>An enumerable of discovered types.</returns> 75 78 IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin); 79 80 /// <summary> 81 /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>. 82 /// </summary> 83 /// <param name="type">The type to discover.</param> 84 /// <param name="plugin">The declaring plugin.</param> 85 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 86 /// <returns>An enumerable of discovered types.</returns> 87 IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable); 88 76 89 /// <summary> 77 90 /// Finds the plugin that declares the <paramref name="type">type</paramref>.
Note: See TracChangeset
for help on using the changeset viewer.