Changeset 5407
- Timestamp:
- 02/03/11 00:56:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab/3.3/Tests/PluginLoader.cs
r5306 r5407 9 9 namespace HeuristicLab_33.Tests { 10 10 internal static class PluginLoader { 11 public const string ExecutableExtension = ".exe"; 11 12 public const string AssemblyExtension = ".dll"; 12 13 public const string TestAccessorAssemblyExtension = "_Accessor.dll"; … … 15 16 16 17 static PluginLoader() { 17 foreach (string path in Directory.EnumerateFiles(Environment.CurrentDirectory) 18 .Where(s => s.EndsWith(AssemblyExtension) && !s.EndsWith(TestAccessorAssemblyExtension) && !s.EndsWith(TestAssemblyExtension))) 19 Assembly.LoadFrom(path); 20 18 foreach (string path in Directory.EnumerateFiles(Environment.CurrentDirectory).Where(s => IsRelevantAssemblyPath(s))) { 19 try { 20 Assembly.LoadFrom(path); 21 } 22 catch (BadImageFormatException) { } 23 } 21 24 Assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); 22 25 } 23 26 27 private static bool IsRelevantAssemblyPath(string path) { 28 bool valid = true; 29 valid = valid && (path.EndsWith(ExecutableExtension, StringComparison.OrdinalIgnoreCase) || path.EndsWith(AssemblyExtension, StringComparison.OrdinalIgnoreCase)); 30 valid = valid && !path.EndsWith(TestAccessorAssemblyExtension, StringComparison.OrdinalIgnoreCase) && !path.EndsWith(TestAssemblyExtension, StringComparison.OrdinalIgnoreCase); 31 return valid; 32 } 33 24 34 public static bool IsPluginAssembly(Assembly assembly) { 25 return assembly.GetExportedTypes() 26 .Where(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).Any(); 35 return assembly.GetExportedTypes().Any(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface); 27 36 } 28 37 }
Note: See TracChangeset
for help on using the changeset viewer.