Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Extensions/TypeExtensions.cs @ 15334

Last change on this file since 15334 was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

File size: 854 bytes
Line 
1using System;
2
3namespace HeuristicLab.Problems.ProgramSynthesis.Base.Extensions {
4  public static class TypeExtensions {
5    public static bool IsSubclass(this Type type, Type baseType) {
6      if (type == null || baseType == null || type == baseType)
7        return false;
8
9      if (baseType.IsGenericType == false) {
10        if (type.IsGenericType == false)
11          return type.IsSubclassOf(baseType);
12      } else {
13        baseType = baseType.GetGenericTypeDefinition();
14      }
15
16      type = type.BaseType;
17      var objectType = typeof(object);
18      while (type != objectType && type != null) {
19        var curentType = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
20        if (curentType == baseType)
21          return true;
22
23        type = type.BaseType;
24      }
25
26      return false;
27    }
28  }
29}
Note: See TracBrowser for help on using the repository browser.