Changeset 8310 for trunk/sources
- Timestamp:
- 07/20/12 08:57:40 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Common/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
r8220 r8310 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 81 81 private static ReferenceEqualityComparer comparer = new ReferenceEqualityComparer();82 82 private static IEnumerable<object> GetChildObjects(object obj, HashSet<object> excludedMembers, bool excludeStaticMembers) { 83 83 Type type = obj.GetType(); … … 86 86 PropertyInfo info = type.GetProperty("Value"); 87 87 object value = info.GetValue(obj, null); 88 if (value != null && !excludedMembers.Contains(value , comparer))88 if (value != null && !excludedMembers.Contains(value)) 89 89 yield return value; 90 90 } else if (type.IsSubclassOfRawGeneric(typeof(Dictionary<,>)) || … … 97 97 var dictionary = obj as IDictionary; 98 98 foreach (object value in dictionary.Keys) { 99 if (excludedMembers.Contains(value , comparer)) continue;99 if (excludedMembers.Contains(value)) continue; 100 100 yield return value; 101 101 } 102 102 foreach (object value in dictionary.Values) { 103 if (excludedMembers.Contains(value , comparer)) continue;103 if (excludedMembers.Contains(value)) continue; 104 104 yield return value; 105 105 } … … 107 107 var enumerable = obj as IEnumerable; 108 108 foreach (var value in enumerable) { 109 if (excludedMembers.Contains(value , comparer)) continue;109 if (excludedMembers.Contains(value)) continue; 110 110 yield return value; 111 111 } … … 116 116 try { 117 117 fieldValue = f.GetValue(obj); 118 } catch (SecurityException) { 118 } 119 catch (SecurityException) { 119 120 continue; 120 121 } 121 if (excludedMembers.Contains(fieldValue , comparer)) continue;122 if (excludedMembers.Contains(fieldValue)) continue; 122 123 yield return fieldValue; 123 124 } -
trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs
r7259 r8310 49 49 50 50 public static IEnumerable<FieldInfo> GetAllFields(this Type type) { 51 foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags. Public | BindingFlags.NonPublic))51 foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic)) 52 52 yield return field; 53 53 54 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags. Public | BindingFlags.NonPublic))54 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic)) 55 55 yield return field; 56 56
Note: See TracChangeset
for help on using the changeset viewer.