Changeset 7111 for trunk/sources/HeuristicLab.PluginInfrastructure
- Timestamp:
- 12/01/11 17:33:56 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.PluginInfrastructure/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Interfaces/IApplicationManager.cs
r5903 r7111 58 58 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 59 59 /// <returns>An enumerable of discovered types.</returns> 60 IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable = true );60 IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false); 61 61 62 62 /// <summary> … … 67 67 /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param> 68 68 /// <returns>An enumerable of discovered types.</returns> 69 IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable = true, bool assignableToAllTypes = true);69 IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true); 70 70 71 71 /// <summary> … … 76 76 /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param> 77 77 /// <returns>An enumerable of discovered types.</returns> 78 IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable = true );78 IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false); 79 79 80 80 /// <summary> … … 86 86 /// /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param> 87 87 /// <returns>An enumerable of discovered types.</returns> 88 IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool assignableToAllTypes = true);88 IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true); 89 89 90 90 /// <summary> -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs
r7069 r7111 73 73 public IEnumerable<object> GetInstances(Type type) { 74 74 List<object> instances = new List<object>(); 75 foreach (Type t in GetTypes(type , true)) {75 foreach (Type t in GetTypes(type)) { 76 76 object instance = null; 77 77 try { instance = Activator.CreateInstance(t); } … … 88 88 /// <remarks>Return only types that are instantiable 89 89 /// (interfaces, abstract classes... are not returned)</remarks> 90 /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param> 90 91 /// <returns>Enumerable of the discovered types.</returns> 91 public IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable = true, bool assignableToAllTypes = true) {92 IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable );92 public IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true) { 93 IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable, includeGenericTypeDefinitions); 93 94 foreach (Type type in types.Skip(1)) { 94 IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable );95 IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions); 95 96 if (assignableToAllTypes) result = result.Intersect(discoveredTypes); 96 97 else result = result.Union(discoveredTypes); … … 105 106 /// <param name="onlyInstantiable">Return only types that are instantiable 106 107 /// (interfaces, abstract classes... are not returned)</param> 108 /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param> 107 109 /// <returns>Enumerable of the discovered types.</returns> 108 public IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable = true ) {110 public IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false) { 109 111 return from asm in AppDomain.CurrentDomain.GetAssemblies() 110 from t in GetTypes(type, asm, onlyInstantiable )112 from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions) 111 113 select t; 112 114 } … … 120 122 /// (interfaces, abstract classes... are not returned)</param> 121 123 /// <returns>Enumerable of the discovered types.</returns> 122 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true ) {124 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false) { 123 125 try { 124 126 var assemblyTypes = assembly.GetTypes(); … … 131 133 132 134 return from t in buildTypes 133 where onlyInstantiable == false|| !t.IsGenericTypeDefinition135 where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition 134 136 select t; 135 137 } … … 182 184 /// <param name="plugin"></param> 183 185 /// <param name="onlyInstantiable"></param> 184 /// <returns></returns> 185 /// <throws>NotSupportedException</throws> 186 public IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable = true) { 186 /// <param name="includeGenericTypeDefinitions"></param> 187 /// <returns></returns> 188 /// <throws>NotSupportedException</throws> 189 public IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false) { 187 190 throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins."); 188 191 } … … 194 197 /// <param name="plugin"></param> 195 198 /// <param name="onlyInstantiable"></param> 196 /// <returns></returns> 197 /// <throws>NotSupportedException</throws> 198 public IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool assignableToAllTypes = true) { 199 /// <param name="includeGenericTypeDefinitions"></param> 200 /// <returns></returns> 201 /// <throws>NotSupportedException</throws> 202 public IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true) { 199 203 throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins."); 200 204 } -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs
r7069 r7111 148 148 internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class { 149 149 List<T> instances = new List<T>(); 150 foreach (Type t in GetTypes(typeof(T), plugin, true)) {150 foreach (Type t in GetTypes(typeof(T), plugin, onlyInstantiable: true, includeGenericTypeDefinitions: false)) { 151 151 T instance = null; 152 152 try { instance = (T)Activator.CreateInstance(t); } … … 164 164 private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class { 165 165 List<T> instances = new List<T>(); 166 foreach (Type t in GetTypes(typeof(T), asm, true)) {166 foreach (Type t in GetTypes(typeof(T), asm, onlyInstantiable: true, includeGenericTypeDefinitions: false)) { 167 167 T instance = null; 168 168 try { instance = (T)Activator.CreateInstance(t); } … … 189 189 internal static IEnumerable<object> GetInstances(Type type) { 190 190 List<object> instances = new List<object>(); 191 foreach (Type t in GetTypes(type, true)) {191 foreach (Type t in GetTypes(type, onlyInstantiable: true, includeGenericTypeDefinitions: false)) { 192 192 object instance = null; 193 193 try { instance = Activator.CreateInstance(t); } … … 203 203 /// <param name="type">Most general type for which to find matching types.</param> 204 204 /// <param name="onlyInstantiable">Return only types that are instantiable 205 /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param> 205 206 /// (interfaces, abstract classes... are not returned)</param> 206 207 /// <returns>Enumerable of the discovered types.</returns> 207 internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable ) {208 internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable, bool includeGenericTypeDefinitions) { 208 209 return from asm in AppDomain.CurrentDomain.GetAssemblies() 209 from t in GetTypes(type, asm, onlyInstantiable )210 from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions) 210 211 select t; 211 212 } 212 213 213 internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool assignableToAllTypes) {214 IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable );214 internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) { 215 IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable, includeGenericTypeDefinitions); 215 216 foreach (Type type in types.Skip(1)) { 216 IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable );217 IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions); 217 218 if (assignableToAllTypes) result = result.Intersect(discoveredTypes); 218 219 else result = result.Union(discoveredTypes); … … 228 229 /// <param name="pluginDescription">The plugin the subtypes must be part of.</param> 229 230 /// <param name="onlyInstantiable">Return only types that are instantiable 231 /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param> 230 232 /// (interfaces, abstract classes... are not returned)</param> 231 233 /// <returns>Enumerable of the discovered types.</returns> 232 internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable ) {234 internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable, bool includeGenericTypeDefinitions) { 233 235 PluginDescription pluginDesc = (PluginDescription)pluginDescription; 234 236 return from asm in AppDomain.CurrentDomain.GetAssemblies() 235 237 where !IsDynamicAssembly(asm) 236 238 where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase)) 237 from t in GetTypes(type, asm, onlyInstantiable )239 from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions) 238 240 select t; 239 241 } 240 242 241 internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription pluginDescription, bool onlyInstantiable, bool assignableToAllTypes) {242 IEnumerable<Type> result = GetTypes(types.First(), pluginDescription, onlyInstantiable );243 internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription pluginDescription, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) { 244 IEnumerable<Type> result = GetTypes(types.First(), pluginDescription, onlyInstantiable, includeGenericTypeDefinitions); 243 245 foreach (Type type in types.Skip(1)) { 244 IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable );246 IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable, includeGenericTypeDefinitions); 245 247 if (assignableToAllTypes) result = result.Intersect(discoveredTypes); 246 248 else result = result.Union(discoveredTypes); … … 260 262 /// <param name="onlyInstantiable">Return only types that are instantiable 261 263 /// (interfaces, abstract classes... are not returned)</param> 264 /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param> 262 265 /// <returns>Enumerable of the discovered types.</returns> 263 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable ) {266 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable, bool includeGenericTypeDefinitions) { 264 267 var buildTypes = from t in assembly.GetTypes() 265 268 where !IsNonDiscoverableType(t) … … 270 273 271 274 return from t in buildTypes 272 where onlyInstantiable == false|| !t.IsGenericTypeDefinition275 where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition 273 276 select t; 274 277 } … … 316 319 } 317 320 318 IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable ) {319 return GetTypes(type, onlyInstantiable );320 } 321 IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool assignableToAllTypes) {322 return GetTypes(types, onlyInstantiable, assignableToAllTypes);323 } 324 325 IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable ) {326 return GetTypes(type, plugin, onlyInstantiable );327 } 328 IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable, bool assignableToAllTypes) {329 return GetTypes(types, plugin, onlyInstantiable, assignableToAllTypes);321 IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable, bool includeGenericTypeDefinitions) { 322 return GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions); 323 } 324 IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) { 325 return GetTypes(types, onlyInstantiable, includeGenericTypeDefinitions, assignableToAllTypes); 326 } 327 328 IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable, bool includeGenericTypeDefinitions) { 329 return GetTypes(type, plugin, onlyInstantiable, includeGenericTypeDefinitions); 330 } 331 IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) { 332 return GetTypes(types, plugin, onlyInstantiable, includeGenericTypeDefinitions, assignableToAllTypes); 330 333 } 331 334
Note: See TracChangeset
for help on using the changeset viewer.