Last change
on this file since 17282 was
17282,
checked in by dpiringe, 5 years ago
|
#3026: changed the converter selection from an automated mechanism (with interface distances) to an explicit mechanism (with priorities)
|
File size:
1.1 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Manufacture {
|
---|
9 | public static class TypeExtensions {
|
---|
10 |
|
---|
11 | public static bool IsEqualTo(this Type type, Type other) {
|
---|
12 | if (other == null) throw new ArgumentNullException("other");
|
---|
13 | if (type == other) return true;
|
---|
14 | if (other.IsInterface && other.IsGenericType)
|
---|
15 | return
|
---|
16 | type.IsAssignableFrom(other) ||
|
---|
17 | type.GetInterfaces()
|
---|
18 | .Where(i => i.IsGenericType)
|
---|
19 | .Any(i => i.GetGenericTypeDefinition() == other);
|
---|
20 | else if (other.IsInterface) {
|
---|
21 | return type.GetInterfaces().Any(i => i == other);
|
---|
22 | }
|
---|
23 |
|
---|
24 | else if (other.IsGenericType) {
|
---|
25 | Type baseType = type;
|
---|
26 | while (baseType != typeof(object)) {
|
---|
27 | if (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == other)
|
---|
28 | return true;
|
---|
29 | baseType = baseType.BaseType;
|
---|
30 | }
|
---|
31 | }
|
---|
32 | return type.IsAssignableFrom(other);
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.