Changeset 7255 for branches/RegressionBenchmarks/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs
- Timestamp:
- 01/02/12 11:40:31 (12 years ago)
- Location:
- branches/RegressionBenchmarks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RegressionBenchmarks
-
branches/RegressionBenchmarks/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs
r7085 r7255 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.