Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/03/18 17:48:20 (6 years ago)
Author:
jkarder
Message:

#2520: worked on new persistence

  • added cache for different attributes
  • refactored StorableTypeBoxTransformer
  • implemented paths for Storable members
  • implemented more unit tests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Core/StorableTypeAttribute.cs

    r15986 r16210  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324
    2425namespace HeuristicLab.Persistence {
    25 
    2626  /// <summary>
    2727  /// Mark a class to be considered by the <c>StorableSerializer</c>.
    2828  /// </summary>
    29   [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
     29  [AttributeUsage(
     30    AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate,
     31    Inherited = false,
     32    AllowMultiple = false
     33  )]
    3034  public sealed class StorableTypeAttribute : Attribute {
     35    private static IDictionary<Type, StorableTypeAttribute> attributeCache = new Dictionary<Type, StorableTypeAttribute>();
    3136
    32 
     37    #region Properties
    3338    /// <summary>
    3439    /// Specify how members are selected for serialization.
     
    3641    public StorableMemberSelection MemberSelection { get; private set; }
    3742
     43    /// <summary>
     44    /// The GUID that identifies the type.
     45    /// </summary>
     46    /// <value>The GUID.</value>
    3847    public Guid Guid { get; private set; }
     48    #endregion
    3949
    4050    /// <summary>
     
    6474    /// <returns></returns>
    6575    public static bool IsStorableType(Type type) {
    66       object[] attribs = type.GetCustomAttributes(typeof(StorableTypeAttribute), false);
    67       return attribs.Length > 0;
     76      return GetStorableTypeAttribute(type) != null;
    6877    }
    6978
    7079    public static StorableTypeAttribute GetStorableTypeAttribute(Type type) {
    71       return (StorableTypeAttribute)Attribute.GetCustomAttribute(type, typeof(StorableTypeAttribute), false);
     80      StorableTypeAttribute attrib;
     81
     82      if (!attributeCache.TryGetValue(type, out attrib)) {
     83        attrib = (StorableTypeAttribute)GetCustomAttribute(type, typeof(StorableTypeAttribute), false);
     84        if (attrib != null) attributeCache[type] = attrib;
     85      }
     86
     87      return attrib;
    7288    }
    73 
    7489  }
    7590}
Note: See TracChangeset for help on using the changeset viewer.