- Timestamp:
- 10/07/11 23:45:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
r6500 r6891 30 30 namespace HeuristicLab.Common { 31 31 public static class ObjectExtensions { 32 public static IEnumerable<object> GetObjectGraphObjects(this object obj ) {32 public static IEnumerable<object> GetObjectGraphObjects(this object obj, bool excludeStaticMembers = false) { 33 33 if (obj == null) return Enumerable.Empty<object>(); 34 34 … … 41 41 objects.Add(current); 42 42 43 foreach (object o in GetChildObjects(current )) {43 foreach (object o in GetChildObjects(current, excludeStaticMembers)) { 44 44 if (o != null && !objects.Contains(o) && !ExcludeType(o.GetType())) 45 45 stack.Push(o); … … 49 49 return objects; 50 50 } 51 51 52 /// <summary> 52 53 /// Types not collected: … … 68 69 (type.HasElementType && ExcludeType(type.GetElementType())); 69 70 } 70 private static IEnumerable<object> GetChildObjects(object obj ) {71 private static IEnumerable<object> GetChildObjects(object obj, bool excludeStaticMembers) { 71 72 Type type = obj.GetType(); 72 73 … … 93 94 } else { 94 95 foreach (FieldInfo f in type.GetAllFields()) { 96 if (excludeStaticMembers && f.IsStatic) continue; 95 97 yield return f.GetValue(obj); 96 98 }
Note: See TracChangeset
for help on using the changeset viewer.