Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14032


Ignore:
Timestamp:
07/09/16 19:40:55 (8 years ago)
Author:
gkronber
Message:

#2626: reverted changes from r13998 and introduce a new attribute (ExcludeFromObjectGraphTraversalAttribute) which can be used to mark fields that should be excluded from object graph traversal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs

    r13998 r14032  
    3030
    3131namespace 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
    3238  public static class ObjectExtensions {
    3339    public static IEnumerable<T> ToEnumerable<T>(this T obj) {
     
    6369    ///   * System.Delegate
    6470    ///   * System.Reflection.Pointer
    65     ///   * System.RuntimeType
    6671    ///   * Primitives (Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, Single)
    6772    ///   * string, decimal, DateTime
     
    8085             typeof(Pointer).IsAssignableFrom(type) ||
    8186             type.Namespace == "System.Reflection.Emit" ||
    82              type.Assembly.GetName().Name == "System.Runtime.Serialization" ||
    83              typeof(TypeInfo).IsAssignableFrom(type) ||
    8487             (type.HasElementType && ExcludeType(type.GetElementType()));
    8588    }
     
    117120      } else {
    118121        if (!fieldInfos.ContainsKey(type))
    119           fieldInfos[type] = type.GetAllFields().ToArray();
     122          fieldInfos[type] = type.GetAllFields()
     123            .Where(fi => !fi.GetCustomAttributes<ExcludeFromObjectGraphTraversalAttribute>().Any())
     124            .ToArray();
    120125        foreach (FieldInfo f in fieldInfos[type]) {
    121126          if (excludeStaticMembers && f.IsStatic) continue;
Note: See TracChangeset for help on using the changeset viewer.