Changeset 14145
- Timestamp:
- 07/21/16 09:53:55 (8 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13998,14032,14144
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Common/3.3/ObjectExtensions.cs
r13879 r14145 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) { … … 113 119 } 114 120 } else { 115 if (!fieldInfos.ContainsKey(type)) 116 fieldInfos[type] = type.GetAllFields().ToArray(); 117 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) { 118 129 if (excludeStaticMembers && f.IsStatic) continue; 119 130 object fieldValue; 120 131 try { 121 132 fieldValue = f.GetValue(obj); 122 } 123 catch (SecurityException) { 133 } catch (SecurityException) { 124 134 continue; 125 135 }
Note: See TracChangeset
for help on using the changeset viewer.