Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17478


Ignore:
Timestamp:
03/17/20 14:55:23 (4 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)
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj

    r17473 r17478  
    6161  </ItemGroup>
    6262  <ItemGroup>
     63    <Compile Include="AdvancedTypeComparer.cs" />
    6364    <Compile Include="Constants.cs" />
    6465    <Compile Include="Converters\AlgorithmConverter.cs" />
     
    99100    <Compile Include="Models\ValueLookupJsonItem.cs" />
    100101    <Compile Include="SingleLineArrayJsonWriter.cs" />
    101     <Compile Include="Extensions\TypeExtensions.cs" />
    102102    <Compile Include="JCGenerator.cs" />
    103103    <Compile Include="JsonTemplateInstantiator.cs" />
     
    166166    </ProjectReference>
    167167  </ItemGroup>
    168   <ItemGroup />
     168  <ItemGroup>
     169    <Folder Include="Extensions\" />
     170  </ItemGroup>
    169171  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    170172  <PropertyGroup>
  • 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.