Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/07/19 23:40:10 (5 years ago)
Author:
mkommend
Message:

#2520: Merged 16565 - 16579 into stable.

Location:
stable
Files:
5 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Persistence

  • stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableMemberInfo.cs

    r15584 r17097  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Reflection;
    2424using System.Text;
    25 using HeuristicLab.Persistence.Core;
     25using HEAL.Attic;
    2626
    2727namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable {
  • stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs

    r15584 r17097  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Linq;
    2525using System.Reflection;
    26 using HeuristicLab.Persistence.Core;
     26using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable {
     
    4343        storableMembers.AddRange(GenerateStorableMembers(type.BaseType));
    4444
    45       var storableClassAttribute = GetStorableClassAttribute(type);
    46       if (storableClassAttribute != null) {
    47         switch (storableClassAttribute.Type) {
    48           case StorableClassType.MarkedOnly:
     45      var storableTypeAttribute = GetStorableTypeAttribute(type);
     46      if (storableTypeAttribute != null) {
     47        switch (storableTypeAttribute.MemberSelection) {
     48          case StorableMemberSelection.MarkedOnly:
    4949            AddMarkedMembers(type, storableMembers); break;
    50           case StorableClassType.AllFields:
     50          case StorableMemberSelection.AllFields:
    5151            AddAll(type, MemberTypes.Field, storableMembers); break;
    52           case StorableClassType.AllProperties:
     52          case StorableMemberSelection.AllProperties:
    5353            AddAll(type, MemberTypes.Property, storableMembers); break;
    54           case StorableClassType.AllFieldsAndAllProperties:
     54          case StorableMemberSelection.AllFieldsAndAllProperties:
    5555            AddAll(type, MemberTypes.Field | MemberTypes.Property, storableMembers); break;
    5656          default:
    57             throw new PersistenceException("unsupported [StorableClassType]: " + storableClassAttribute.Type);
     57            throw new PersistenceException("unsupported [StorableMemberSelection]: " + storableTypeAttribute.MemberSelection);
    5858        }
    5959      }
     
    6262
    6363    public static bool IsEmptyOrStorableType(Type type, bool recursive) {
    64       if (!HasStorableClassAttribute(type) && !IsEmptyType(type, false)) return false;
     64      if (!HasStorableTypeAttribute(type) && !IsEmptyType(type, false)) return false;
    6565      return !recursive || type.BaseType == null || IsEmptyOrStorableType(type.BaseType, true);
    6666    }
     
    7272        foreach (var hook in CollectHooks(hookType, type.BaseType))
    7373          yield return hook;
    74       if (HasStorableClassAttribute(type)) {
     74      if (HasStorableTypeAttribute(type)) {
    7575        foreach (MethodInfo methodInfo in type.GetMethods(DECLARED_INSTANCE_MEMBERS)) {
    7676          if (methodInfo.ReturnType == typeof(void) && methodInfo.GetParameters().Length == 0) {
     
    174174    #region [StorableClass] helpers
    175175
    176     private static StorableClassAttribute GetStorableClassAttribute(Type type) {
    177       lock (storableClassCache) {
    178         if (storableClassCache.ContainsKey(type))
    179           return storableClassCache[type];
    180         StorableClassAttribute attribute = type
    181           .GetCustomAttributes(typeof(StorableClassAttribute), false)
    182           .SingleOrDefault() as StorableClassAttribute;
    183         storableClassCache.Add(type, attribute);
     176    private static StorableTypeAttribute GetStorableTypeAttribute(Type type) {
     177      lock (storableTypeCache) {
     178        if (storableTypeCache.ContainsKey(type))
     179          return storableTypeCache[type];
     180        StorableTypeAttribute attribute = type
     181          .GetCustomAttributes(typeof(StorableTypeAttribute), false)
     182          .SingleOrDefault() as StorableTypeAttribute;
     183        storableTypeCache.Add(type, attribute);
    184184        return attribute;
    185185      }
    186186    }
    187187
    188     public static bool HasStorableClassAttribute(Type type) {
    189       return GetStorableClassAttribute(type) != null;
    190     }
    191 
    192     private static Dictionary<Type, StorableClassAttribute> storableClassCache =
    193       new Dictionary<Type, StorableClassAttribute>();
     188    public static bool HasStorableTypeAttribute(Type type) {
     189      return GetStorableTypeAttribute(type) != null;
     190    }
     191
     192    private static Dictionary<Type, StorableTypeAttribute> storableTypeCache =
     193      new Dictionary<Type, StorableTypeAttribute>();
    194194
    195195    #endregion
  • stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs

    r15584 r17097  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626using System.Reflection.Emit;
    2727using System.Text;
     28using HEAL.Attic;
    2829using HeuristicLab.Persistence.Core;
    2930using HeuristicLab.Persistence.Interfaces;
     
    3839  /// or <c>AllFieldsAndAllProperties</c>.
    3940  /// </summary>
    40   [StorableClass]
     41  [StorableType("F60343E8-4337-4171-A50A-6A57D09267ED")]
    4142  public sealed class StorableSerializer : ICompositeSerializer {
    4243
     
    4950
    5051    [StorableConstructor]
    51     private StorableSerializer(bool deserializing) : this() { }
     52    private StorableSerializer(StorableConstructorFlag _) { }
    5253
    5354    #region ICompositeSerializer implementation
     
    6970    /// </returns>
    7071    public bool CanSerialize(Type type) {
    71       var markedStorable = StorableReflection.HasStorableClassAttribute(type);
     72      if (type.IsEnum || type.IsValueType) return false; // there are other more specific serializers for enums and structs
     73      var markedStorable = StorableReflection.HasStorableTypeAttribute(type);
    7274      if (GetConstructor(type) == null)
    73         if (markedStorable)
     75        if (markedStorable && !type.IsInterface)
    7476          throw new Exception("[Storable] type has no default constructor and no [StorableConstructor]");
    7577        else
    7678          return false;
    7779      if (!StorableReflection.IsEmptyOrStorableType(type, true))
    78         if (markedStorable)
     80        if (markedStorable && !type.IsInterface)
    7981          throw new Exception("[Storable] type has non emtpy, non [Storable] base classes");
    8082        else
     
    240242        .Where(ci => ci.GetCustomAttributes(typeof(StorableConstructorAttribute), false).Length > 0)) {
    241243        if (ci.GetParameters().Length != 1 ||
    242             ci.GetParameters()[0].ParameterType != typeof(bool))
    243           throw new PersistenceException("StorableConstructor must have exactly one argument of type bool");
     244            ci.GetParameters()[0].ParameterType != typeof(StorableConstructorFlag))
     245          throw new PersistenceException("StorableConstructor must have exactly one argument of type StorableConstructorFlag");
    244246        var dm = new DynamicMethod("", typeof(object), null, type, true);
    245247        var ilgen = dm.GetILGenerator();
    246         ilgen.Emit(OpCodes.Ldc_I4_1); // load true
     248        var defaultFlagFieldInfo = typeof(StorableConstructorFlag).GetField("Default", BindingFlags.Static | BindingFlags.Public);
     249        ilgen.Emit(OpCodes.Ldsfld, defaultFlagFieldInfo); // load the object
    247250        ilgen.Emit(OpCodes.Newobj, ci);
    248251        ilgen.Emit(OpCodes.Ret);
Note: See TracChangeset for help on using the changeset viewer.