Changeset 8212
- Timestamp:
- 07/04/12 13:09:14 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
r8128 r8212 35 35 } 36 36 37 public static IEnumerable<object> GetObjectGraphObjects(this object obj, HashSet< string> excludedMembers = null, bool excludeStaticMembers = false) {37 public static IEnumerable<object> GetObjectGraphObjects(this object obj, HashSet<object> excludedMembers = null, bool excludeStaticMembers = false) { 38 38 if (obj == null) return Enumerable.Empty<object>(); 39 if (excludedMembers == null) excludedMembers = new HashSet< string>();39 if (excludedMembers == null) excludedMembers = new HashSet<object>(); 40 40 41 41 var objects = new HashSet<object>(); … … 78 78 (type.HasElementType && ExcludeType(type.GetElementType())); 79 79 } 80 private static IEnumerable<object> GetChildObjects(object obj, HashSet<string> excludedMembers, bool excludeStaticMembers) { 80 81 private static ReferenceEqualityComparer comparer = new ReferenceEqualityComparer(); 82 private static IEnumerable<object> GetChildObjects(object obj, HashSet<object> excludedMembers, bool excludeStaticMembers) { 81 83 Type type = obj.GetType(); 82 84 … … 84 86 PropertyInfo info = type.GetProperty("Value"); 85 87 object value = info.GetValue(obj, null); 86 if (value != null) yield return value; 88 if (value != null && excludedMembers.Contains(value, comparer)) 89 yield return value; 87 90 } else if (type.IsSubclassOfRawGeneric(typeof(Dictionary<,>)) || 88 91 type.IsSubclassOfRawGeneric(typeof(SortedDictionary<,>)) || … … 93 96 obj is Hashtable) { 94 97 var dictionary = obj as IDictionary; 95 foreach (object value in dictionary.Keys) 98 foreach (object value in dictionary.Keys) { 99 if (excludedMembers.Contains(value, comparer)) continue; 96 100 yield return value; 97 foreach (object value in dictionary.Values) 101 } 102 foreach (object value in dictionary.Values) { 103 if (excludedMembers.Contains(value, comparer)) continue; 98 104 yield return value; 105 } 99 106 } else if (type.IsArray || type.IsSubclassOfRawGeneric(typeof(HashSet<>))) { 100 107 var enumerable = obj as IEnumerable; 101 foreach (var value in enumerable) 108 foreach (var value in enumerable) { 109 if (excludedMembers.Contains(value, comparer)) continue; 102 110 yield return value; 111 } 103 112 } else { 104 113 foreach (FieldInfo f in type.GetAllFields()) { 105 if (excludedMembers.Contains(f.Name)) continue;106 114 if (excludeStaticMembers && f.IsStatic) continue; 107 115 object fieldValue; … … 112 120 continue; 113 121 } 122 if (excludedMembers.Contains(fieldValue, comparer)) continue; 114 123 yield return fieldValue; 115 124 } -
trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
r8155 r8212 273 273 protected virtual void OnPrepared() { 274 274 ExecutionTime = TimeSpan.Zero; 275 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet< string>() { "runs"}).OfType<IStatefulItem>()) {275 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet<object>() { Runs }).OfType<IStatefulItem>()) { 276 276 statefulObject.InitializeState(); 277 277 } … … 294 294 public event EventHandler Stopped; 295 295 protected virtual void OnStopped() { 296 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet< string>() { "runs"}).OfType<IStatefulItem>()) {296 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet<object>() { Runs }).OfType<IStatefulItem>()) { 297 297 statefulObject.ClearState(); 298 298 }
Note: See TracChangeset
for help on using the changeset viewer.