Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/25/19 17:18:41 (5 years ago)
Author:
dpiringe
Message:

#3026

  • deleted IItemExtensions.cs
  • fixed a bug in GetInterfaceDistance in TypeExtensions.cs -> generic types were ignored
  • lots of code clean ups
  • added new transformers: ParameterizedItemTransformer, MultiCheckedOperatorTransformer
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Extensions
Files:
1 deleted
1 edited

Legend:

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

    r17266 r17269  
    44using System.Text;
    55using System.Threading.Tasks;
     6using HeuristicLab.Core;
    67
    78namespace HeuristicLab.Manufacture {
     
    910    public static int GetInterfaceDistance(this Type type, Type interfaceType) {
    1011      if (!interfaceType.IsInterface) return -1;
    11       int distance = 0;
     12      int distance = int.MaxValue;
    1213      Type baseType = type;
    1314      while (baseType != typeof(object)) {
    1415        var interfaces = baseType.GetInterfaces();
    1516        var minimalInterfaces = interfaces.Except(interfaces.SelectMany(i => i.GetInterfaces()));
    16         if (baseType == interfaceType && minimalInterfaces.Any(i => i == interfaceType))
    17           ++distance;
     17        if (minimalInterfaces.Any(i => {
     18          if (i.IsGenericType)
     19            return i.GetGenericTypeDefinition() == interfaceType;
     20          return i == interfaceType;
     21        })) --distance;
    1822        baseType = baseType.BaseType;
    1923      }
    2024      return distance;
    2125    }
     26
    2227    public static bool IsEqualTo(this Type type, Type other) {
    2328      if (other == null) throw new ArgumentNullException("other");
     
    3035            .Any(i => i.GetGenericTypeDefinition() == other);
    3136      else if (other.IsInterface) {
    32         /*
    33         Type baseType = type;
    34         while (baseType != typeof(object)) {
    35           var interfaces = baseType.GetInterfaces();
    36           var minimalInterfaces = interfaces.Except(interfaces.SelectMany(i => i.GetInterfaces()));
    37           if (baseType == other && minimalInterfaces.Any(i => i == other))
    38             return true;
    39           baseType = baseType.BaseType;
    40         }
    41         */
    4237        return type.GetInterfaces().Any(i => i == other);
    4338      }
Note: See TracChangeset for help on using the changeset viewer.