Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/05/17 17:36:50 (7 years ago)
Author:
jkarder
Message:

#2520: worked on persistence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TypeInfo.cs

    r13347 r14549  
    7272        while (types.Count > 0) {
    7373          type = types.Pop();
    74           var fieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic).
    75                            Where(x => StorableAttribute.IsStorable(x));
    76           foreach (var field in fieldInfos) {
    77             var attrib = StorableAttribute.GetStorableAttribute(field);
    78             var name = string.IsNullOrEmpty(attrib.Name) ? field.Name : attrib.Name;
    79             fields.Add(new ComponentInfo(name, field, attrib, true, true));
     74          if (StorableClassAttribute.Type != StorableClassType.AllProperties) {
     75            var fieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic)
     76                                 .Where(x => !x.Name.StartsWith("<") && !x.Name.EndsWith("k__BackingField")); // exclude backing fields
     77            if (StorableClassAttribute.Type == StorableClassType.MarkedOnly)
     78              fieldInfos = fieldInfos.Where(x => StorableAttribute.IsStorable(x)).ToArray();
     79            foreach (var field in fieldInfos) {
     80              var attrib = StorableAttribute.GetStorableAttribute(field);
     81              var name = attrib == null || string.IsNullOrEmpty(attrib.Name) ? field.Name : attrib.Name;
     82              fields.Add(new ComponentInfo(type.Name + '.' + name, field, attrib, true, true));
     83            }
    8084          }
    8185
    82           var propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic).
    83                       Where(x => x.GetIndexParameters().Length == 0).  // exclude indexed properties
    84                       Where(x => StorableAttribute.IsStorable(x));
    85           foreach (var property in propertyInfos) {
    86             var attrib = StorableAttribute.GetStorableAttribute(property);
    87             var name = string.IsNullOrEmpty(attrib.Name) ? property.Name : attrib.Name;
    88             properties.Add(new ComponentInfo(name, property, attrib, property.CanRead, property.CanWrite));
     86          if (StorableClassAttribute.Type != StorableClassType.AllFields) {
     87            var propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic).
     88                        Where(x => x.GetIndexParameters().Length == 0);  // exclude indexed properties
     89            if (StorableClassAttribute.Type == StorableClassType.MarkedOnly)
     90              propertyInfos = propertyInfos.Where(x => StorableAttribute.IsStorable(x)).ToArray();
     91            foreach (var property in propertyInfos) {
     92              var attrib = StorableAttribute.GetStorableAttribute(property);
     93              var name = attrib == null || string.IsNullOrEmpty(attrib.Name) ? property.Name : attrib.Name;
     94              properties.Add(new ComponentInfo(type.Name + '.' + name, property, attrib, property.CanRead, property.CanWrite));
     95            }
    8996          }
    9097
Note: See TracChangeset for help on using the changeset viewer.