Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.