Changeset 3828 for trunk/sources


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

Enabled application managers to discover generic types (#1015)

Location:
trunk/sources/HeuristicLab.PluginInfrastructure
Files:
2 edited

Legend:

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

    r3821 r3828  
    242242             where CheckTypeCompatibility(type, t)
    243243             where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
    244              select BuildType(type, t);
     244             select BuildType(t, type);
    245245    }
    246246
     
    256256      return false;
    257257    }
    258     private static Type BuildType(Type type, Type other) {
    259       if (type.IsGenericType && other.IsGenericType)
    260         return other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments());
     258    private static Type BuildType(Type type, Type protoType) {
     259      if (type.IsGenericType && protoType.IsGenericType)
     260        return type.GetGenericTypeDefinition().MakeGenericType(protoType.GetGenericArguments());
    261261      else
    262         return other;
     262        return type;
    263263    }
    264264
  • 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.