Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3821


Ignore:
Timestamp:
05/17/10 02:00:58 (14 years ago)
Author:
swagner
Message:

Implemented first draft solution for #1015.

File:
1 edited

Legend:

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

    r3247 r3821  
    240240    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
    241241      return from t in assembly.GetTypes()
    242              where type.IsAssignableFrom(t)
     242             where CheckTypeCompatibility(type, t)
    243243             where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
    244              select t;
     244             select BuildType(type, t);
     245    }
     246
     247    private static bool CheckTypeCompatibility(Type type, Type other) {
     248      if (type.IsAssignableFrom(other))
     249        return true;
     250      if (type.IsGenericType && other.IsGenericType) {
     251        try {
     252          if (type.IsAssignableFrom(other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments())))
     253            return true;
     254        } catch (Exception) { }
     255      }
     256      return false;
     257    }
     258    private static Type BuildType(Type type, Type other) {
     259      if (type.IsGenericType && other.IsGenericType)
     260        return other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments());
     261      else
     262        return other;
    245263    }
    246264
Note: See TracChangeset for help on using the changeset viewer.