Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11771


Ignore:
Timestamp:
01/15/15 20:27:59 (10 years ago)
Author:
mkommend
Message:

#2294: Implemented type discovery within certain assemblies in ApplicationManagers.

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

Legend:

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

    r11171 r11771  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Reflection;
    2425
    2526namespace HeuristicLab.PluginInfrastructure {
     
    7071
    7172    /// <summary>
    72     /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
     73    /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly) that are declared in any assembly of <paramref name="plugin"/>.
    7374    /// </summary>
    7475    /// <param name="type">The type to discover.</param>
     
    7980
    8081    /// <summary>
    81     /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
     82    /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly) that are declared in any assembly of <paramref name="plugin"/>.
    8283    /// </summary>
    8384    /// <param name="types">The types to discover.</param>
     
    8788    /// <returns>An enumerable of discovered types.</returns>
    8889    IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true);
     90
     91
     92    /// <summary>
     93    /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly) that are declared in the<paramref name="assembly"/>.
     94    /// </summary>
     95    /// <param name="type">The type to discover.</param>
     96    /// <param name="assembly">The declaring assembly.</param>
     97    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
     98    /// <returns>An enumerable of discovered types.</returns>
     99    IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false);
     100
     101    /// <summary>
     102    /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
     103    /// </summary>
     104    /// <param name="types">The types to discover.</param>
     105    /// <param name="assembly">The declaring assembly.</param>
     106    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
     107    /// /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
     108    /// <returns>An enumerable of discovered types.</returns>
     109    IEnumerable<Type> GetTypes(IEnumerable<Type> types, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true);
    89110
    90111    /// <summary>
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs

    r11171 r11771  
    122122    /// (interfaces, abstract classes...  are not returned)</param>
    123123    /// <returns>Enumerable of the discovered types.</returns>
    124     private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false) {
     124    public IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false) {
    125125      try {
    126126        // necessary to make sure the exception is immediately thrown
     
    148148
    149149    /// <summary>
     150    /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
     151    /// </summary>
     152    /// <param name="types">The types to discover.</param>
     153    /// <param name="assembly">The declaring assembly.</param>
     154    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
     155    /// /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
     156    /// <returns>An enumerable of discovered types.</returns>
     157    public IEnumerable<Type> GetTypes(IEnumerable<Type> types, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true) {
     158      IEnumerable<Type> result = GetTypes(types.First(), assembly, onlyInstantiable, includeGenericTypeDefinitions);
     159      foreach (Type type in types.Skip(1)) {
     160        IEnumerable<Type> discoveredTypes = GetTypes(type, assembly, onlyInstantiable, includeGenericTypeDefinitions);
     161        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
     162        else result = result.Union(discoveredTypes);
     163      }
     164      return result;
     165    }
     166
     167    /// <summary>
    150168    /// Not supported by the LightweightApplicationManager
    151169    /// </summary>
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r11171 r11771  
    260260    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    261261    /// <returns>Enumerable of the discovered types.</returns>
    262     private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
     262    internal static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
    263263      var matchingTypes = from assemblyType in assembly.GetTypes()
    264264                          let t = assemblyType.BuildType(type)
     
    273273    }
    274274
     275    /// <summary>
     276    /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
     277    /// </summary>
     278    /// <param name="types">The types to discover.</param>
     279    /// <param name="assembly">The declaring assembly.</param>
     280    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
     281    /// /// <param name="assignableToAllTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
     282    /// <returns>An enumerable of discovered types.</returns>
     283    internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true) {
     284      IEnumerable<Type> result = GetTypes(types.First(), assembly, onlyInstantiable, includeGenericTypeDefinitions);
     285      foreach (Type type in types.Skip(1)) {
     286        IEnumerable<Type> discoveredTypes = GetTypes(type, assembly, onlyInstantiable, includeGenericTypeDefinitions);
     287        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
     288        else result = result.Union(discoveredTypes);
     289      }
     290      return result;
     291    }
     292
    275293    private void OnPluginLoaded(PluginInfrastructureEventArgs e) {
    276294      if (PluginLoaded != null) PluginLoaded(this, e);
     
    303321    IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) {
    304322      return GetTypes(types, plugin, onlyInstantiable, includeGenericTypeDefinitions, assignableToAllTypes);
     323    }
     324
     325    IEnumerable<Type> IApplicationManager.GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false) {
     326      return GetTypes(type, assembly, onlyInstantiable, includeGenericTypeDefinitions);
     327    }
     328    IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, Assembly assembly, bool onlyInstantiable = true, bool includeGenericTypeDefinitions = false, bool assignableToAllTypes = true) {
     329      return GetTypes(types, assembly, onlyInstantiable, includeGenericTypeDefinitions);
    305330    }
    306331
Note: See TracChangeset for help on using the changeset viewer.