- Timestamp:
- 07/07/19 23:40:10 (5 years ago)
- Location:
- stable
- Files:
-
- 5 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
-
stable/HeuristicLab.Persistence
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableMemberInfo.cs
r15584 r17097 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.Reflection; 24 24 using System.Text; 25 using H euristicLab.Persistence.Core;25 using HEAL.Attic; 26 26 27 27 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { -
stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs
r15584 r17097 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Linq; 25 25 using System.Reflection; 26 using H euristicLab.Persistence.Core;26 using HEAL.Attic; 27 27 28 28 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { … … 43 43 storableMembers.AddRange(GenerateStorableMembers(type.BaseType)); 44 44 45 var storable ClassAttribute = GetStorableClassAttribute(type);46 if (storable ClassAttribute != null) {47 switch (storable ClassAttribute.Type) {48 case Storable ClassType.MarkedOnly:45 var storableTypeAttribute = GetStorableTypeAttribute(type); 46 if (storableTypeAttribute != null) { 47 switch (storableTypeAttribute.MemberSelection) { 48 case StorableMemberSelection.MarkedOnly: 49 49 AddMarkedMembers(type, storableMembers); break; 50 case Storable ClassType.AllFields:50 case StorableMemberSelection.AllFields: 51 51 AddAll(type, MemberTypes.Field, storableMembers); break; 52 case Storable ClassType.AllProperties:52 case StorableMemberSelection.AllProperties: 53 53 AddAll(type, MemberTypes.Property, storableMembers); break; 54 case Storable ClassType.AllFieldsAndAllProperties:54 case StorableMemberSelection.AllFieldsAndAllProperties: 55 55 AddAll(type, MemberTypes.Field | MemberTypes.Property, storableMembers); break; 56 56 default: 57 throw new PersistenceException("unsupported [Storable ClassType]: " + storableClassAttribute.Type);57 throw new PersistenceException("unsupported [StorableMemberSelection]: " + storableTypeAttribute.MemberSelection); 58 58 } 59 59 } … … 62 62 63 63 public static bool IsEmptyOrStorableType(Type type, bool recursive) { 64 if (!HasStorable ClassAttribute(type) && !IsEmptyType(type, false)) return false;64 if (!HasStorableTypeAttribute(type) && !IsEmptyType(type, false)) return false; 65 65 return !recursive || type.BaseType == null || IsEmptyOrStorableType(type.BaseType, true); 66 66 } … … 72 72 foreach (var hook in CollectHooks(hookType, type.BaseType)) 73 73 yield return hook; 74 if (HasStorable ClassAttribute(type)) {74 if (HasStorableTypeAttribute(type)) { 75 75 foreach (MethodInfo methodInfo in type.GetMethods(DECLARED_INSTANCE_MEMBERS)) { 76 76 if (methodInfo.ReturnType == typeof(void) && methodInfo.GetParameters().Length == 0) { … … 174 174 #region [StorableClass] helpers 175 175 176 private static Storable ClassAttribute GetStorableClassAttribute(Type type) {177 lock (storable ClassCache) {178 if (storable ClassCache.ContainsKey(type))179 return storable ClassCache[type];180 Storable ClassAttribute attribute = type181 .GetCustomAttributes(typeof(Storable ClassAttribute), false)182 .SingleOrDefault() as Storable ClassAttribute;183 storable ClassCache.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); 184 184 return attribute; 185 185 } 186 186 } 187 187 188 public static bool HasStorable ClassAttribute(Type type) {189 return GetStorable ClassAttribute(type) != null;190 } 191 192 private static Dictionary<Type, Storable ClassAttribute> storableClassCache =193 new Dictionary<Type, Storable ClassAttribute>();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>(); 194 194 195 195 #endregion -
stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs
r15584 r17097 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 26 26 using System.Reflection.Emit; 27 27 using System.Text; 28 using HEAL.Attic; 28 29 using HeuristicLab.Persistence.Core; 29 30 using HeuristicLab.Persistence.Interfaces; … … 38 39 /// or <c>AllFieldsAndAllProperties</c>. 39 40 /// </summary> 40 [Storable Class]41 [StorableType("F60343E8-4337-4171-A50A-6A57D09267ED")] 41 42 public sealed class StorableSerializer : ICompositeSerializer { 42 43 … … 49 50 50 51 [StorableConstructor] 51 private StorableSerializer( bool deserializing) : this() { }52 private StorableSerializer(StorableConstructorFlag _) { } 52 53 53 54 #region ICompositeSerializer implementation … … 69 70 /// </returns> 70 71 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); 72 74 if (GetConstructor(type) == null) 73 if (markedStorable )75 if (markedStorable && !type.IsInterface) 74 76 throw new Exception("[Storable] type has no default constructor and no [StorableConstructor]"); 75 77 else 76 78 return false; 77 79 if (!StorableReflection.IsEmptyOrStorableType(type, true)) 78 if (markedStorable )80 if (markedStorable && !type.IsInterface) 79 81 throw new Exception("[Storable] type has non emtpy, non [Storable] base classes"); 80 82 else … … 240 242 .Where(ci => ci.GetCustomAttributes(typeof(StorableConstructorAttribute), false).Length > 0)) { 241 243 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"); 244 246 var dm = new DynamicMethod("", typeof(object), null, type, true); 245 247 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 247 250 ilgen.Emit(OpCodes.Newobj, ci); 248 251 ilgen.Emit(OpCodes.Ret);
Note: See TracChangeset
for help on using the changeset viewer.