Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5407 for trunk/sources


Ignore:
Timestamp:
02/03/11 00:56:23 (14 years ago)
Author:
swagner
Message:

Adapted PluginLoader to ignore cases in assembly paths, additionally load exe-files and ignore assemblies which cannot be loaded (#1351)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab/3.3/Tests/PluginLoader.cs

    r5306 r5407  
    99namespace HeuristicLab_33.Tests {
    1010  internal static class PluginLoader {
     11    public const string ExecutableExtension = ".exe";
    1112    public const string AssemblyExtension = ".dll";
    1213    public const string TestAccessorAssemblyExtension = "_Accessor.dll";
     
    1516
    1617    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      }
    2124      Assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
    2225    }
    2326
     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
    2434    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);
    2736    }
    2837  }
Note: See TracChangeset for help on using the changeset viewer.