Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5131 for trunk/sources


Ignore:
Timestamp:
12/17/10 16:22:57 (14 years ago)
Author:
swagner
Message:

Fixed exceptions in plugin infrastructure when trying to instantiate types which do not provide a parameterless constructor (#1309).

Location:
trunk/sources/HeuristicLab.PluginInfrastructure/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/DefaultApplicationManager.cs

    r4482 r5131  
    158158    /// <returns>Enumerable of the created instances.</returns>
    159159    internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class {
    160       return from t in GetTypes(typeof(T), plugin, true)
    161              select (T)Activator.CreateInstance(t);
     160      List<T> instances = new List<T>();
     161      foreach (Type t in GetTypes(typeof(T), plugin, true)) {
     162        T instance = null;
     163        try { instance = (T)Activator.CreateInstance(t); }
     164        catch { }
     165        if (instance != null) instances.Add(instance);
     166      }
     167      return instances;
    162168    }
    163169    /// <summary>
     
    168174    /// <returns>Enumerable of the created instances.</returns>
    169175    private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class {
    170       return from t in GetTypes(typeof(T), asm, true)
    171              select (T)Activator.CreateInstance(t);
     176      List<T> instances = new List<T>();
     177      foreach (Type t in GetTypes(typeof(T), asm, true)) {
     178        T instance = null;
     179        try { instance = (T)Activator.CreateInstance(t); }
     180        catch { }
     181        if (instance != null) instances.Add(instance);
     182      }
     183      return instances;
    172184    }
    173185    /// <summary>
     
    187199    /// <returns>Enumerable of the created instances.</returns>
    188200    internal static IEnumerable<object> GetInstances(Type type) {
    189       return (from t in GetTypes(type, true)
    190               select Activator.CreateInstance(t)).ToList();
     201      List<object> instances = new List<object>();
     202      foreach (Type t in GetTypes(type, true)) {
     203        object instance = null;
     204        try { instance = Activator.CreateInstance(t); }
     205        catch { }
     206        if (instance != null) instances.Add(instance);
     207      }
     208      return instances;
    191209    }
    192210
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs

    r4482 r5131  
    7272    /// <returns>Enumerable of the created instances.</returns>
    7373    public IEnumerable<object> GetInstances(Type type) {
    74       return from t in GetTypes(type, true)
    75              select Activator.CreateInstance(t);
     74      List<object> instances = new List<object>();
     75      foreach (Type t in GetTypes(type, true)) {
     76        object instance = null;
     77        try { instance = Activator.CreateInstance(t); }
     78        catch { }
     79        if (instance != null) instances.Add(instance);
     80      }
     81      return instances;
    7682    }
    7783
Note: See TracChangeset for help on using the changeset viewer.