Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14144


Ignore:
Timestamp:
07/21/16 07:17:25 (8 years ago)
Author:
abeham
Message:

#2626: some minor changes and speed improvements

File:
1 edited

Legend:

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

    r14032 r14144  
    3131namespace HeuristicLab.Common {
    3232
    33   [AttributeUsage(System.AttributeTargets.Field)]
     33  [AttributeUsage(AttributeTargets.Field)]
    3434  // this attribute can be used to mark fields that should be excluded from object graph traversal
    3535  public class ExcludeFromObjectGraphTraversalAttribute : Attribute {
     
    119119        }
    120120      } else {
    121         if (!fieldInfos.ContainsKey(type))
    122           fieldInfos[type] = type.GetAllFields()
    123             .Where(fi => !fi.GetCustomAttributes<ExcludeFromObjectGraphTraversalAttribute>().Any())
     121        FieldInfo[] fieldInfo;
     122        if (!fieldInfos.TryGetValue(type, out fieldInfo)) {
     123          fieldInfo = type.GetAllFields()
     124            .Where(fi => !Attribute.IsDefined(fi, typeof(ExcludeFromObjectGraphTraversalAttribute)))
    124125            .ToArray();
    125         foreach (FieldInfo f in fieldInfos[type]) {
     126          fieldInfos.Add(type, fieldInfo);
     127        }
     128        foreach (FieldInfo f in fieldInfo) {
    126129          if (excludeStaticMembers && f.IsStatic) continue;
    127130          object fieldValue;
    128131          try {
    129132            fieldValue = f.GetValue(obj);
    130           }
    131           catch (SecurityException) {
     133          } catch (SecurityException) {
    132134            continue;
    133135          }
Note: See TracChangeset for help on using the changeset viewer.