Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/12 17:07:13 (12 years ago)
Author:
mkommend
Message:

#1774: Improved performance of type discovery for generic types.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r7259 r7492  
    267267      var buildTypes = from t in assembly.GetTypes()
    268268                       where !IsNonDiscoverableType(t)
    269                        where CheckTypeCompatibility(type, t)
    270269                       where onlyInstantiable == false ||
    271270                             (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
     271                       where CheckTypeCompatibility(type, t)
    272272                       select BuildType(t, type);
    273273
     
    286286        return true;
    287287      if (type.IsGenericType && other.IsGenericType) {
     288        var otherGenericArguments = other.GetGenericArguments();
     289        var typeGenericArguments = type.GetGenericArguments();
     290
     291        //check type arguments count
     292        if (otherGenericArguments.Length != typeGenericArguments.Length)
     293          return false;
     294
     295        //check type arguments & constraints
     296        int i = 0;
     297        foreach (var genericArgument in typeGenericArguments) {
     298          if (otherGenericArguments[i].IsGenericParameter) {
     299            foreach (var constraint in otherGenericArguments[i].GetGenericParameterConstraints())
     300              if (!constraint.IsAssignableFrom(genericArgument)) return false;
     301          } else if (genericArgument != otherGenericArguments[i]) return false;
     302          i++;
     303        }
     304        //check types
    288305        try {
    289           if (type.IsAssignableFrom(other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments())))
     306          var otherGenericTypeDefinition = other.GetGenericTypeDefinition();
     307          if (type.IsAssignableFrom(otherGenericTypeDefinition.MakeGenericType(typeGenericArguments)))
    290308            return true;
    291309        }
Note: See TracChangeset for help on using the changeset viewer.