Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/17/10 23:27:03 (14 years ago)
Author:
swagner
Message:

Enabled application managers to discover generic types (#1015)

File:
1 edited

Legend:

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

    r3247 r3828  
    109109    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
    110110      return from t in assembly.GetTypes()
    111              where type.IsAssignableFrom(t)
     111             where CheckTypeCompatibility(type, t)
    112112             where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
    113              select t;
     113             select BuildType(t, type);
     114    }
     115
     116    private static bool CheckTypeCompatibility(Type type, Type other) {
     117      if (type.IsAssignableFrom(other))
     118        return true;
     119      if (type.IsGenericType && other.IsGenericType) {
     120        try {
     121          if (type.IsAssignableFrom(other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments())))
     122            return true;
     123        }
     124        catch (Exception) { }
     125      }
     126      return false;
     127    }
     128    private static Type BuildType(Type type, Type protoType) {
     129      if (type.IsGenericType && protoType.IsGenericType)
     130        return type.GetGenericTypeDefinition().MakeGenericType(protoType.GetGenericArguments());
     131      else
     132        return type;
    114133    }
    115134
Note: See TracChangeset for help on using the changeset viewer.