Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Common/3.3/ObjectExtensions.cs
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Common/3.3/ObjectExtensions.cs
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 31 31 namespace HeuristicLab.Common { 32 33 [AttributeUsage(AttributeTargets.Field)] 34 // this attribute can be used to mark fields that should be excluded from object graph traversal 35 public class ExcludeFromObjectGraphTraversalAttribute : Attribute { 36 } 37 32 38 public static class ObjectExtensions { 33 39 public static IEnumerable<T> ToEnumerable<T>(this T obj) { … … 66 72 /// * string, decimal, DateTime 67 73 /// * Arrays of types not collected 74 /// * All types from System.Reflection.Emit 68 75 /// </summary> 69 76 private static bool ExcludeType(Type type) { … … 77 84 typeof(Delegate).IsAssignableFrom(type) || 78 85 typeof(Pointer).IsAssignableFrom(type) || 79 type == typeof(System.Reflection.Emit.SignatureHelper)||86 type.Namespace == "System.Reflection.Emit" || 80 87 (type.HasElementType && ExcludeType(type.GetElementType())); 81 88 } … … 112 119 } 113 120 } else { 114 if (!fieldInfos.ContainsKey(type)) 115 fieldInfos[type] = type.GetAllFields().ToArray(); 116 foreach (FieldInfo f in fieldInfos[type]) { 121 FieldInfo[] fieldInfo; 122 if (!fieldInfos.TryGetValue(type, out fieldInfo)) { 123 fieldInfo = type.GetAllFields() 124 .Where(fi => !Attribute.IsDefined(fi, typeof(ExcludeFromObjectGraphTraversalAttribute))) 125 .ToArray(); 126 fieldInfos.Add(type, fieldInfo); 127 } 128 foreach (FieldInfo f in fieldInfo) { 117 129 if (excludeStaticMembers && f.IsStatic) continue; 118 130 object fieldValue; 119 131 try { 120 132 fieldValue = f.GetValue(obj); 121 } 122 catch (SecurityException) { 133 } catch (SecurityException) { 123 134 continue; 124 135 }
Note: See TracChangeset
for help on using the changeset viewer.