Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.