Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6201 for trunk/sources


Ignore:
Timestamp:
05/16/11 13:24:56 (14 years ago)
Author:
mkommend
Message:

#1522: Updated object graph traversing.

Location:
trunk/sources
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs

    r6192 r6201  
    2121
    2222using System;
    23 using System.Collections;
    2423using System.Collections.Generic;
    2524using System.Reflection;
    26 using System.Threading;
     25using System.Collections;
    2726
    2827namespace HeuristicLab.Common {
     
    4645    private static void CollectObjectGraphObjects(this object obj, HashSet<object> objects) {
    4746      if (obj == null || objects.Contains(obj)) return;
    48       if (obj is Delegate || obj is EventHandler) return;
     47      if (obj is Delegate || obj is EventHandler) return;
     48      if (obj is Pointer) return;
    4949      Type type = obj.GetType();
    5050      if (type.IsSubclassOfRawGeneric(typeof(EventHandler<>))) return;
    5151      if (type.IsPrimitive || type == typeof(string) || type == typeof(decimal)) return;
    52       if (type.IsArray) {
     52      if (type.HasElementType) {
    5353        Type elementType = type.GetElementType();
    5454        if (elementType.IsPrimitive || elementType == typeof(string) || elementType == typeof(decimal)) return;
     55        //TODO check all types
    5556      }
    5657
    5758      objects.Add(obj);
    5859
    59       if (typeof(Type).IsInstanceOfType(obj)) return; // avoid infinite recursion
    60       if (type.IsSubclassOfRawGeneric(typeof(ThreadLocal<>))) return; // avoid stack overflow when the field `ConcurrentStack<int> s_availableIndices` grows large
     60      //if (typeof(Type).IsInstanceOfType(obj)) return; // avoid infinite recursion
     61      //if (type.IsSubclassOfRawGeneric(typeof(ThreadLocal<>))) return; // avoid stack overflow when the field `ConcurrentStack<int> s_availableIndices` grows large
    6162
    6263      // performance critical to handle dictionaries in a special way
    6364      var dictionary = obj as IDictionary;
    6465      if (dictionary != null) {
    65         foreach (object value in dictionary.Keys) {
     66        foreach (object value in dictionary.Keys)
    6667          CollectObjectGraphObjects(value, objects);
    67         }
    68         foreach (object value in dictionary.Values) {
     68        foreach (object value in dictionary.Values)
    6969          CollectObjectGraphObjects(value, objects);
    70         }
    7170        return;
    72       }
    73 
    74       if (type.IsArray) {
     71      } else if (type.IsArray) {
    7572        var array = obj as Array;
    76         foreach (object value in array) {
     73        foreach (object value in array)
    7774          CollectObjectGraphObjects(value, objects);
    78         }
    7975        return;
    8076      }
     
    8278      foreach (FieldInfo f in type.GetAllFields()) {
    8379        f.GetValue(obj).CollectObjectGraphObjects(objects);
    84       }     
     80      }
    8581    }
    8682  }
  • trunk/sources/HeuristicLab/3.3/Tests/HeuristicLab-3.3.Tests.csproj

    r6036 r6201  
    123123  <ItemGroup>
    124124    <Compile Include="CloningConstructorTest.cs" />
     125    <Compile Include="CollectObjectGraphTest.cs" />
    125126    <Compile Include="ContentViewTests.cs" />
    126127    <Compile Include="SymbolicRegressionTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.