Changeset 11203 for branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers
- Timestamp:
- 07/18/14 12:35:00 (11 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll11 10 HeuristicLab 3.3.5.1.ReSharper.user 12 11 HeuristicLab 3.3.6.0.ReSharper.user 13 12 HeuristicLab.4.5.resharper.user 14 13 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development16 14 HeuristicLab.resharper.user 17 15 ProtoGen.exe … … 19 17 _ReSharper.HeuristicLab 20 18 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests22 19 _ReSharper.HeuristicLab.ExtLibs 23 20 bin 24 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Persistence
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/ArraySerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/CompactNumberArray2StringSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/ConcreteDictionarySerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/DictionarySerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/EnumSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/EnumerableSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/HashSetSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/KeyValuePairSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Number2StringSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 78 78 /// </returns> 79 79 public bool CanSerialize(Type type) { 80 return numberSerializerMap.ContainsKey( Nullable.GetUnderlyingType(type) ??type);80 return numberSerializerMap.ContainsKey(type); 81 81 } 82 82 … … 90 90 /// </returns> 91 91 public string JustifyRejection(Type type) { 92 return string.Format("not a (nullable)number type (one of {0})",92 return string.Format("not a number type (one of {0})", 93 93 string.Join(", ", numberSerializers.Select(n => n.SourceType.Name).ToArray())); 94 94 } … … 100 100 /// <returns></returns> 101 101 public string Format(object obj) { 102 if (obj == null) return "null"; 103 Type type = obj.GetType(); 104 return ((XmlString)numberSerializerMap[Nullable.GetUnderlyingType(type) ?? type].Format(obj)).Data; 102 return ((XmlString)numberSerializerMap[obj.GetType()].Format(obj)).Data; 105 103 } 106 104 … … 112 110 /// <returns></returns> 113 111 public object Parse(string stringValue, Type type) { 114 if (stringValue == "null") return null;115 112 try { 116 return numberSerializerMap[ Nullable.GetUnderlyingType(type) ??type].Parse(new XmlString(stringValue));113 return numberSerializerMap[type].Parse(new XmlString(stringValue)); 117 114 } 118 115 catch (FormatException e) { -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/NumberEnumerable2StringSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/StackSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableAttribute.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableClassAttribute.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableClassType.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableConstructorAttribute.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableHookAttribute.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableMemberInfo.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 47 47 hookCache = new Dictionary<HookDesignator, List<StorableReflection.Hook>>(); 48 48 } 49 50 49 [StorableConstructor] 51 50 private StorableSerializer(bool deserializing) : this() { } … … 69 68 /// </returns> 70 69 public bool CanSerialize(Type type) { 71 varmarkedStorable = StorableReflection.HasStorableClassAttribute(type);70 bool markedStorable = StorableReflection.HasStorableClassAttribute(type); 72 71 if (GetConstructor(type) == null) 73 72 if (markedStorable) … … 92 91 /// </returns> 93 92 public string JustifyRejection(Type type) { 94 var sb = new StringBuilder();93 StringBuilder sb = new StringBuilder(); 95 94 if (GetConstructor(type) == null) 96 95 sb.Append("class has no default constructor and no [StorableConstructor]"); … … 118 117 /// <returns>An enumerable of <see cref="Tag"/>s.</returns> 119 118 public IEnumerable<Tag> Decompose(object obj) { 120 return from accessor in GetStorableAccessors(obj.GetType()) 121 where accessor.Get != null 122 select new Tag(accessor.Name, accessor.Get(obj)); 119 foreach (var accessor in GetStorableAccessors(obj.GetType())) { 120 if (accessor.Get != null) 121 yield return new Tag(accessor.Name, accessor.Get(obj)); 122 } 123 123 } 124 124 … … 147 147 public void Populate(object instance, IEnumerable<Tag> objects, Type type) { 148 148 var memberDict = new Dictionary<string, Tag>(); 149 variter = objects.GetEnumerator();149 IEnumerator<Tag> iter = objects.GetEnumerator(); 150 150 while (iter.MoveNext()) { 151 151 memberDict.Add(iter.Current.Name, iter.Current); … … 170 170 BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; 171 171 172 private sealed class HookDesignator : Tuple<Type, HookType> { 173 public HookDesignator(Type type, HookType hookType) : base(type, hookType) { } 172 private static readonly object[] emptyArgs = new object[] { }; 173 private static readonly object[] trueArgs = new object[] { true }; 174 175 private sealed class HookDesignator { 176 public Type Type { get; private set; } 177 public HookType HookType { get; private set; } 178 public HookDesignator() { } 179 public HookDesignator(Type type, HookType hookType) { 180 Type = type; 181 HookType = HookType; 182 } 174 183 } 175 184 … … 182 191 #region caches 183 192 184 private readonlyAccessorListCache accessorListCache;185 private readonlyAccessorCache accessorCache;186 private readonlyDictionary<Type, Constructor> constructorCache;187 private readonlyDictionary<HookDesignator, List<StorableReflection.Hook>> hookCache;193 private AccessorListCache accessorListCache; 194 private AccessorCache accessorCache; 195 private Dictionary<Type, Constructor> constructorCache; 196 private Dictionary<HookDesignator, List<StorableReflection.Hook>> hookCache; 188 197 189 198 #endregion … … 197 206 var storableMembers = StorableReflection 198 207 .GenerateStorableMembers(type) 199 .Select(GetMemberAccessor) 200 .ToList(); 208 .Select(mi => GetMemberAccessor(mi)); 201 209 accessorListCache[type] = storableMembers; 202 210 return storableMembers; … … 208 216 if (accessorCache.ContainsKey(mi.MemberInfo)) 209 217 return new DataMemberAccessor(accessorCache[mi.MemberInfo], mi.DisentangledName, mi.DefaultValue); 210 var dma = new DataMemberAccessor(mi.MemberInfo, mi.DisentangledName, mi.DefaultValue);218 DataMemberAccessor dma = new DataMemberAccessor(mi.MemberInfo, mi.DisentangledName, mi.DefaultValue); 211 219 accessorCache[mi.MemberInfo] = dma; 212 220 return dma; … … 218 226 if (constructorCache.ContainsKey(type)) 219 227 return constructorCache[type]; 220 var c = FindStorableConstructor(type) ?? GetDefaultConstructor(type);228 Constructor c = FindStorableConstructor(type) ?? GetDefaultConstructor(type); 221 229 constructorCache.Add(type, c); 222 230 return c; … … 225 233 226 234 private Constructor GetDefaultConstructor(Type type) { 227 varci = type.GetConstructor(ALL_CONSTRUCTORS, null, Type.EmptyTypes, null);235 ConstructorInfo ci = type.GetConstructor(ALL_CONSTRUCTORS, null, Type.EmptyTypes, null); 228 236 if (ci == null) 229 237 return null; 230 vardm = new DynamicMethod("", typeof(object), null, type, true);231 var ilgen = dm.GetILGenerator();238 DynamicMethod dm = new DynamicMethod("", typeof(object), null, type, true); 239 ILGenerator ilgen = dm.GetILGenerator(); 232 240 ilgen.Emit(OpCodes.Newobj, ci); 233 241 ilgen.Emit(OpCodes.Ret); … … 236 244 237 245 private Constructor FindStorableConstructor(Type type) { 238 foreach ( var ci in type239 .GetConstructors(ALL_CONSTRUCTORS)240 .Where(ci => ci.GetCustomAttributes(typeof(StorableConstructorAttribute), false).Length > 0)) {241 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 var dm = new DynamicMethod("", typeof(object), null, type, true);245 var ilgen = dm.GetILGenerator();246 ilgen.Emit(OpCodes.Ldc_I4_1); // load true247 ilgen.Emit(OpCodes.Newobj, ci);248 ilgen.Emit(OpCodes.Ret);249 return (Constructor)dm.CreateDelegate(typeof(Constructor));246 foreach (ConstructorInfo ci in type.GetConstructors(ALL_CONSTRUCTORS)) { 247 if (ci.GetCustomAttributes(typeof(StorableConstructorAttribute), false).Length > 0) { 248 if (ci.GetParameters().Length != 1 || 249 ci.GetParameters()[0].ParameterType != typeof(bool)) 250 throw new PersistenceException("StorableConstructor must have exactly one argument of type bool"); 251 DynamicMethod dm = new DynamicMethod("", typeof(object), null, type, true); 252 ILGenerator ilgen = dm.GetILGenerator(); 253 ilgen.Emit(OpCodes.Ldc_I4_1); // load true 254 ilgen.Emit(OpCodes.Newobj, ci); 255 ilgen.Emit(OpCodes.Ret); 256 return (Constructor)dm.CreateDelegate(typeof(Constructor)); 257 } 250 258 } 251 259 return null; … … 254 262 private void InvokeHook(HookType hookType, object obj) { 255 263 if (obj == null) 256 throw new ArgumentNullException(" obj");257 foreach ( varhook in GetHooks(hookType, obj.GetType())) {264 throw new ArgumentNullException("Cannot invoke hooks on null"); 265 foreach (StorableReflection.Hook hook in GetHooks(hookType, obj.GetType())) { 258 266 hook(obj); 259 267 } -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/StructSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/TupleSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/TypeSerializer.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab.
Note: See TracChangeset
for help on using the changeset viewer.