Changeset 6201
- Timestamp:
- 05/16/11 13:24:56 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
r6192 r6201 21 21 22 22 using System; 23 using System.Collections;24 23 using System.Collections.Generic; 25 24 using System.Reflection; 26 using System. Threading;25 using System.Collections; 27 26 28 27 namespace HeuristicLab.Common { … … 46 45 private static void CollectObjectGraphObjects(this object obj, HashSet<object> objects) { 47 46 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; 49 49 Type type = obj.GetType(); 50 50 if (type.IsSubclassOfRawGeneric(typeof(EventHandler<>))) return; 51 51 if (type.IsPrimitive || type == typeof(string) || type == typeof(decimal)) return; 52 if (type. IsArray) {52 if (type.HasElementType) { 53 53 Type elementType = type.GetElementType(); 54 54 if (elementType.IsPrimitive || elementType == typeof(string) || elementType == typeof(decimal)) return; 55 //TODO check all types 55 56 } 56 57 57 58 objects.Add(obj); 58 59 59 if (typeof(Type).IsInstanceOfType(obj)) return; // avoid infinite recursion60 if (type.IsSubclassOfRawGeneric(typeof(ThreadLocal<>))) return; // avoid stack overflow when the field `ConcurrentStack<int> s_availableIndices` grows large60 //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 61 62 62 63 // performance critical to handle dictionaries in a special way 63 64 var dictionary = obj as IDictionary; 64 65 if (dictionary != null) { 65 foreach (object value in dictionary.Keys) {66 foreach (object value in dictionary.Keys) 66 67 CollectObjectGraphObjects(value, objects); 67 } 68 foreach (object value in dictionary.Values) { 68 foreach (object value in dictionary.Values) 69 69 CollectObjectGraphObjects(value, objects); 70 }71 70 return; 72 } 73 74 if (type.IsArray) { 71 } else if (type.IsArray) { 75 72 var array = obj as Array; 76 foreach (object value in array) {73 foreach (object value in array) 77 74 CollectObjectGraphObjects(value, objects); 78 }79 75 return; 80 76 } … … 82 78 foreach (FieldInfo f in type.GetAllFields()) { 83 79 f.GetValue(obj).CollectObjectGraphObjects(objects); 84 } 80 } 85 81 } 86 82 } -
trunk/sources/HeuristicLab/3.3/Tests/HeuristicLab-3.3.Tests.csproj
r6036 r6201 123 123 <ItemGroup> 124 124 <Compile Include="CloningConstructorTest.cs" /> 125 <Compile Include="CollectObjectGraphTest.cs" /> 125 126 <Compile Include="ContentViewTests.cs" /> 126 127 <Compile Include="SymbolicRegressionTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.