Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/11 11:04:02 (13 years ago)
Author:
cneumuel
Message:

#1424

  • created extension method GetObjectGraphObjects for objects
  • created IStatefulItem interface, which means an object has a state which can be initialized and cleared
  • after an algorithm stopped, all objects of the algorithm-objectgraph with the type IStatefulItem are cleared
  • on prepare, all IStatefulItem objects are initialized
Location:
trunk/sources/HeuristicLab.Common/3.3
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r5837 r6103  
    121121    <Compile Include="Content\IStorableContent.cs" />
    122122    <Compile Include="Constants.cs" />
     123    <Compile Include="ObjectExtensions.cs" />
    123124    <Compile Include="DeepCloneable.cs" />
    124125    <Compile Include="Content\IContent.cs" />
  • trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs

    r5445 r6103  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Reflection;
    2325using System.Text;
    2426
     
    4547      return sb.ToString();
    4648    }
     49    public static IEnumerable<FieldInfo> GetAllFields(this Type type) {
     50      foreach(var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
     51        yield return field;
     52
     53      foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
     54        yield return field;
     55     
     56      if (type.BaseType != null) {
     57        foreach (var field in type.BaseType.GetAllFields())
     58          yield return field;
     59      }
     60    }
     61    // http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class
     62    public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic) {
     63      while (toCheck != typeof(object)) {
     64        var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
     65        if (generic == cur) {
     66          return true;
     67        }
     68        toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface
     69        if (toCheck == null)
     70          return false;
     71      }
     72      return false;
     73    }
    4774  }
    4875}
Note: See TracChangeset for help on using the changeset viewer.