Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/20 14:55:23 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • removed type extension for type comparison (was a complicated comparison, which should not be a public extension method for Type)
    • comparison is now located (as private method) in JsonItemConverter
    • also simplified it a lot (did some tests to measure the relevance of specific checks -> last check got completely removed)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItemConverter.cs

    r17439 r17478  
    4040     
    4141      foreach (var x in Converters)
    42         if (type.IsEqualTo(x.Key))
     42        if (CompareTypes(type, x.Key))
    4343          possibleConverters.Add(x.Value);
    4444
     
    9191      Converters = converters;
    9292    }
     93
     94    private bool CompareGenericTypes(Type t1, Type t2) =>
     95      (t1.IsGenericType && t1.GetGenericTypeDefinition() == t2) ||
     96      (t2.IsGenericType && t2.GetGenericTypeDefinition() == t1);
     97
     98    private bool CompareTypes(Type t1, Type t2) =>
     99      t1 == t2 || t1.IsAssignableFrom(t2) ||
     100      t1.GetInterfaces().Any(
     101        i => i == t2 || CompareGenericTypes(i, t2)
     102      ) ||
     103      CompareGenericTypes(t1, t2);
    93104  }
    94105}
Note: See TracChangeset for help on using the changeset viewer.