- Timestamp:
- 09/14/12 18:58:15 (12 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GP-MoveOperators/HeuristicLab.Common/3.3/ObjectExtensions.cs
r8206 r8660 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>(); … … 48 48 49 49 foreach (object o in GetChildObjects(current, excludedMembers, excludeStaticMembers)) { 50 if (o != null && !objects.Contains(o) && !ExcludeType(o.GetType())) 51 stack.Push(o); 50 if (o == null) continue; 51 if (ExcludeType(o.GetType())) continue; 52 if (objects.Contains(o)) continue; 53 stack.Push(o); 52 54 } 53 55 } … … 63 65 /// * string, decimal, DateTime 64 66 /// * Arrays of types not collected 65 ///66 /// Dictionaries and HashSets are treated specially, because it is cheaper to iterate over their keys and values67 /// compared to traverse their internal data structures.68 67 /// </summary> 69 68 private static bool ExcludeType(Type type) { 70 69 return type.IsPrimitive || 71 70 type == typeof(string) || 71 type == typeof(string[]) || 72 72 type == typeof(decimal) || 73 type == typeof(decimal[]) || 73 74 type == typeof(DateTime) || 75 type == typeof(DateTime[]) || 74 76 typeof(Delegate).IsAssignableFrom(type) || 75 77 typeof(Pointer).IsAssignableFrom(type) || 76 type == typeof(string[]) || 77 type == typeof(DateTime[]) || 78 type == typeof(System.Reflection.Emit.SignatureHelper) || 78 79 (type.HasElementType && ExcludeType(type.GetElementType())); 79 80 } 80 private static IEnumerable<object> GetChildObjects(object obj, HashSet<string> excludedMembers, bool excludeStaticMembers) { 81 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)) 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)) 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)) 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)) 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)) continue; 114 123 yield return fieldValue; 115 124 }
Note: See TracChangeset
for help on using the changeset viewer.