Last change
on this file since 17454 was
17287,
checked in by dpiringe, 5 years ago
|
#3026
- added class for constants -> Constants
- added new converter -> ValueLookupParameterConverter
- fixed a bug with type extension IsEqualTo
- fixed converter priorities
|
File size:
1.1 KB
|
Rev | Line | |
---|
[17263] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
[17269] | 6 | using HeuristicLab.Core;
|
---|
[17263] | 7 |
|
---|
[17284] | 8 | namespace HeuristicLab.JsonInterface {
|
---|
[17263] | 9 | public static class TypeExtensions {
|
---|
[17269] | 10 |
|
---|
[17263] | 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 | }
|
---|
[17287] | 32 | return false;//type.IsAssignableFrom(other);
|
---|
[17263] | 33 | }
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.