Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/01/19 14:29:59 (5 years ago)
Author:
dpiringe
Message:

#3026: changed the converter selection from an automated mechanism (with interface distances) to an explicit mechanism (with priorities)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Extensions/TypeExtensions.cs

    r17269 r17282  
    88namespace HeuristicLab.Manufacture {
    99  public static class TypeExtensions {
    10     public static int GetInterfaceDistance(this Type type, Type interfaceType) {
    11       if (!interfaceType.IsInterface) return -1;
    12       int distance = int.MaxValue;
    13       Type baseType = type;
    14       while (baseType != typeof(object)) {
    15         var interfaces = baseType.GetInterfaces();
    16         var minimalInterfaces = interfaces.Except(interfaces.SelectMany(i => i.GetInterfaces()));
    17         if (minimalInterfaces.Any(i => {
    18           if (i.IsGenericType)
    19             return i.GetGenericTypeDefinition() == interfaceType;
    20           return i == interfaceType;
    21         })) --distance;
    22         baseType = baseType.BaseType;
    23       }
    24       return distance;
    25     }
    2610
    2711    public static bool IsEqualTo(this Type type, Type other) {
Note: See TracChangeset for help on using the changeset viewer.