Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/11 17:33:56 (13 years ago)
Author:
mkommend
Message:

#1689: Corrected ApplicationManagers by introducing a new parameter in the GetTypes method.

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  
    5858    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
    5959    /// <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);
    6161
    6262    /// <summary>
     
    6767    /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
    6868    /// <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);
    7070
    7171    /// <summary>
     
    7676    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
    7777    /// <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);
    7979
    8080    /// <summary>
     
    8686    /// /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
    8787    /// <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);
    8989
    9090    /// <summary>
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs

    r7069 r7111  
    7373    public IEnumerable<object> GetInstances(Type type) {
    7474      List<object> instances = new List<object>();
    75       foreach (Type t in GetTypes(type, true)) {
     75      foreach (Type t in GetTypes(type)) {
    7676        object instance = null;
    7777        try { instance = Activator.CreateInstance(t); }
     
    8888    /// <remarks>Return only types that are instantiable
    8989    /// (interfaces, abstract classes... are not returned)</remarks>
     90    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    9091    /// <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);
    9394      foreach (Type type in types.Skip(1)) {
    94         IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable);
     95        IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions);
    9596        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
    9697        else result = result.Union(discoveredTypes);
     
    105106    /// <param name="onlyInstantiable">Return only types that are instantiable
    106107    /// (interfaces, abstract classes... are not returned)</param>
     108    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    107109    /// <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) {
    109111      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    110              from t in GetTypes(type, asm, onlyInstantiable)
     112             from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions)
    111113             select t;
    112114    }
     
    120122    /// (interfaces, abstract classes...  are not returned)</param>
    121123    /// <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) {
    123125      try {
    124126        var assemblyTypes = assembly.GetTypes();
     
    131133
    132134        return from t in buildTypes
    133                where onlyInstantiable == false || !t.IsGenericTypeDefinition
     135               where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition
    134136               select t;
    135137      }
     
    182184    /// <param name="plugin"></param>
    183185    /// <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) {
    187190      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
    188191    }
     
    194197    /// <param name="plugin"></param>
    195198    /// <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) {
    199203      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
    200204    }
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r7069 r7111  
    148148    internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class {
    149149      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)) {
    151151        T instance = null;
    152152        try { instance = (T)Activator.CreateInstance(t); }
     
    164164    private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class {
    165165      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)) {
    167167        T instance = null;
    168168        try { instance = (T)Activator.CreateInstance(t); }
     
    189189    internal static IEnumerable<object> GetInstances(Type type) {
    190190      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)) {
    192192        object instance = null;
    193193        try { instance = Activator.CreateInstance(t); }
     
    203203    /// <param name="type">Most general type for which to find matching types.</param>
    204204    /// <param name="onlyInstantiable">Return only types that are instantiable
     205    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    205206    /// (interfaces, abstract classes... are not returned)</param>
    206207    /// <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) {
    208209      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    209              from t in GetTypes(type, asm, onlyInstantiable)
     210             from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions)
    210211             select t;
    211212    }
    212213
    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);
    215216      foreach (Type type in types.Skip(1)) {
    216         IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable);
     217        IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions);
    217218        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
    218219        else result = result.Union(discoveredTypes);
     
    228229    /// <param name="pluginDescription">The plugin the subtypes must be part of.</param>
    229230    /// <param name="onlyInstantiable">Return only types that are instantiable
     231    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    230232    /// (interfaces, abstract classes... are not returned)</param>
    231233    /// <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) {
    233235      PluginDescription pluginDesc = (PluginDescription)pluginDescription;
    234236      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    235237             where !IsDynamicAssembly(asm)
    236238             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)
    238240             select t;
    239241    }
    240242
    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);
    243245      foreach (Type type in types.Skip(1)) {
    244         IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable);
     246        IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable, includeGenericTypeDefinitions);
    245247        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
    246248        else result = result.Union(discoveredTypes);
     
    260262    /// <param name="onlyInstantiable">Return only types that are instantiable
    261263    /// (interfaces, abstract classes...  are not returned)</param>
     264    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    262265    /// <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) {
    264267      var buildTypes = from t in assembly.GetTypes()
    265268                       where !IsNonDiscoverableType(t)
     
    270273
    271274      return from t in buildTypes
    272              where onlyInstantiable == false || !t.IsGenericTypeDefinition
     275             where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition
    273276             select t;
    274277    }
     
    316319    }
    317320
    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);
    330333    }
    331334
Note: See TracChangeset for help on using the changeset viewer.