- Timestamp:
- 03/15/12 09:11:17 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Common/3.3/ObjectExtensions.cs
r7268 r7615 31 31 namespace HeuristicLab.Common { 32 32 public static class ObjectExtensions { 33 public static IEnumerable<object> GetObjectGraphObjects(this object obj, bool excludeStaticMembers = false) {33 public static IEnumerable<object> GetObjectGraphObjects(this object obj, HashSet<string> excludedMembers = null, bool excludeStaticMembers = false) { 34 34 if (obj == null) return Enumerable.Empty<object>(); 35 if (excludedMembers == null) excludedMembers = new HashSet<string>(); 35 36 36 37 var objects = new HashSet<object>(); … … 42 43 objects.Add(current); 43 44 44 foreach (object o in GetChildObjects(current, exclude StaticMembers)) {45 foreach (object o in GetChildObjects(current, excludedMembers, excludeStaticMembers)) { 45 46 if (o != null && !objects.Contains(o) && !ExcludeType(o.GetType())) 46 47 stack.Push(o); … … 70 71 (type.HasElementType && ExcludeType(type.GetElementType())); 71 72 } 72 private static IEnumerable<object> GetChildObjects(object obj, bool excludeStaticMembers) {73 private static IEnumerable<object> GetChildObjects(object obj, HashSet<string> excludedMembers, bool excludeStaticMembers) { 73 74 Type type = obj.GetType(); 74 75 … … 95 96 } else { 96 97 foreach (FieldInfo f in type.GetAllFields()) { 98 if (excludedMembers.Contains(f.Name)) continue; 97 99 if (excludeStaticMembers && f.IsStatic) continue; 98 100 object fieldValue; 99 101 try { 100 102 fieldValue = f.GetValue(obj); 101 } catch (SecurityException) { 103 } 104 catch (SecurityException) { 102 105 continue; 103 106 }
Note: See TracChangeset
for help on using the changeset viewer.