- Timestamp:
- 09/25/19 17:18:41 (5 years ago)
- 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 4 4 using System.Text; 5 5 using System.Threading.Tasks; 6 using HeuristicLab.Core; 6 7 7 8 namespace HeuristicLab.Manufacture { … … 9 10 public static int GetInterfaceDistance(this Type type, Type interfaceType) { 10 11 if (!interfaceType.IsInterface) return -1; 11 int distance = 0;12 int distance = int.MaxValue; 12 13 Type baseType = type; 13 14 while (baseType != typeof(object)) { 14 15 var interfaces = baseType.GetInterfaces(); 15 16 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; 18 22 baseType = baseType.BaseType; 19 23 } 20 24 return distance; 21 25 } 26 22 27 public static bool IsEqualTo(this Type type, Type other) { 23 28 if (other == null) throw new ArgumentNullException("other"); … … 30 35 .Any(i => i.GetGenericTypeDefinition() == other); 31 36 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 */42 37 return type.GetInterfaces().Any(i => i == other); 43 38 }
Note: See TracChangeset
for help on using the changeset viewer.