- Timestamp:
- 08/06/13 16:36:11 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Common/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
r9456 r9855 38 38 if (obj == null) return Enumerable.Empty<object>(); 39 39 if (excludedMembers == null) excludedMembers = new HashSet<object>(); 40 var fieldInfos = new Dictionary<Type, FieldInfo[]>(); 40 41 41 42 var objects = new HashSet<object>(); … … 47 48 objects.Add(current); 48 49 49 foreach (object o in GetChildObjects(current, excludedMembers, excludeStaticMembers )) {50 foreach (object o in GetChildObjects(current, excludedMembers, excludeStaticMembers, fieldInfos)) { 50 51 if (o == null) continue; 51 52 if (ExcludeType(o.GetType())) continue; … … 80 81 } 81 82 82 private static IEnumerable<object> GetChildObjects(object obj, HashSet<object> excludedMembers, bool excludeStaticMembers ) {83 private static IEnumerable<object> GetChildObjects(object obj, HashSet<object> excludedMembers, bool excludeStaticMembers, Dictionary<Type, FieldInfo[]> fieldInfos) { 83 84 Type type = obj.GetType(); 84 85 … … 111 112 } 112 113 } else { 113 foreach (FieldInfo f in type.GetAllFields()) { 114 if (!fieldInfos.ContainsKey(type)) 115 fieldInfos[type] = type.GetAllFields().ToArray(); 116 foreach (FieldInfo f in fieldInfos[type]) { 114 117 if (excludeStaticMembers && f.IsStatic) continue; 115 118 object fieldValue; -
trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs
r9456 r9855 49 49 50 50 public static IEnumerable<FieldInfo> GetAllFields(this Type type) { 51 foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic)) 52 yield return field; 53 54 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic)) 55 yield return field; 56 57 if (type.BaseType != null) { 58 foreach (var field in type.BaseType.GetAllFields()) 51 while (type != null) { 52 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic)) 59 53 yield return field; 54 type = type.BaseType; 60 55 } 61 56 }
Note: See TracChangeset
for help on using the changeset viewer.