- Timestamp:
- 07/09/16 19:40:55 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
r13998 r14032 30 30 31 31 namespace HeuristicLab.Common { 32 33 [AttributeUsage(System.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) { … … 63 69 /// * System.Delegate 64 70 /// * System.Reflection.Pointer 65 /// * System.RuntimeType66 71 /// * Primitives (Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, Single) 67 72 /// * string, decimal, DateTime … … 80 85 typeof(Pointer).IsAssignableFrom(type) || 81 86 type.Namespace == "System.Reflection.Emit" || 82 type.Assembly.GetName().Name == "System.Runtime.Serialization" ||83 typeof(TypeInfo).IsAssignableFrom(type) ||84 87 (type.HasElementType && ExcludeType(type.GetElementType())); 85 88 } … … 117 120 } else { 118 121 if (!fieldInfos.ContainsKey(type)) 119 fieldInfos[type] = type.GetAllFields().ToArray(); 122 fieldInfos[type] = type.GetAllFields() 123 .Where(fi => !fi.GetCustomAttributes<ExcludeFromObjectGraphTraversalAttribute>().Any()) 124 .ToArray(); 120 125 foreach (FieldInfo f in fieldInfos[type]) { 121 126 if (excludeStaticMembers && f.IsStatic) continue;
Note: See TracChangeset
for help on using the changeset viewer.