Index: branches/PersistenceOverhaul/HeuristicLab 3.3.sln
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab 3.3.sln	(revision 13325)
+++ branches/PersistenceOverhaul/HeuristicLab 3.3.sln	(revision 13326)
@@ -449,4 +449,6 @@
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.ALPS-3.3", "HeuristicLab.Algorithms.ALPS\3.3\HeuristicLab.Algorithms.ALPS-3.3.csproj", "{59F354CB-FE13-4253-AED2-AD86372BEC27}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Persistence-4.0", "HeuristicLab.Persistence\4.0\HeuristicLab.Persistence-4.0.csproj", "{B1663091-8156-4DEB-9E37-5B19810A4644}"
 EndProject
 Global
@@ -2188,4 +2190,12 @@
 		{59F354CB-FE13-4253-AED2-AD86372BEC27}.Release|x86.ActiveCfg = Release|x86
 		{59F354CB-FE13-4253-AED2-AD86372BEC27}.Release|x86.Build.0 = Release|x86
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Release|Any CPU.Build.0 = Release|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Release|x64.ActiveCfg = Release|Any CPU
+		{B1663091-8156-4DEB-9E37-5B19810A4644}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/BinarySerializer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/BinarySerializer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/BinarySerializer.cs	(revision 13326)
@@ -0,0 +1,38 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  public sealed class BinarySerializer : Serializer {
+    protected override void SerializePersistenceBundle(PersistenceBundle bundle, Stream stream) {
+      var formatter = new BinaryFormatter();
+      formatter.Serialize(stream, bundle);
+    }
+
+    protected override PersistenceBundle DeserializePersistenceBundle(Stream stream) {
+      var formatter = new BinaryFormatter();
+      return (PersistenceBundle)formatter.Deserialize(stream);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ComponentInfo.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ComponentInfo.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ComponentInfo.cs	(revision 13326)
@@ -0,0 +1,41 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Reflection;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Persistence {
+  public sealed class ComponentInfo {
+    public string Name { get; private set; }
+    public MemberInfo MemberInfo { get; private set; }
+    public StorableAttribute StorableAttribute { get; private set; }
+    public bool Readable { get; private set; }
+    public bool Writeable { get; private set; }
+
+    public ComponentInfo(string name, MemberInfo memberInfo, StorableAttribute storableAttribute, bool readable, bool writeable) {
+      Name = name;
+      MemberInfo = memberInfo;
+      StorableAttribute = storableAttribute;
+      Readable = readable;
+      Writeable = writeable;
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/CustomTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/CustomTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/CustomTransformer.cs	(revision 13326)
@@ -0,0 +1,48 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  public abstract class CustomTransformer<TSource> : ITransformer {
+    public Guid Guid { get; private set; }
+    public ushort Id { get; private set; }
+    public ushort Order { get; private set; }
+
+    protected CustomTransformer() {
+      Guid = TransformerAttribute.GetGuid(this.GetType());
+      Order = TransformerAttribute.GetOrder(this.GetType());
+      Id = 0;
+    }
+
+    public void Initialize(ushort id) {
+      Id = id;
+    }
+
+    public bool CanTransformType(Type type) {
+      return type == typeof(TSource);
+    }
+
+    public abstract PersistenceData ToData(object o, PersistenceMapper mapper);
+    public abstract object ToObject(PersistenceData data, PersistenceMapper mapper);
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Index.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Index.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Index.cs	(revision 13326)
@@ -0,0 +1,66 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Persistence {
+  [NonDiscoverableType]
+  internal sealed class Index<T> where T : class {
+    private Dictionary<T, uint> indexes;
+    private Dictionary<uint, T> values;
+    private uint nextIndex;
+
+    public Index() {
+      indexes = new Dictionary<T, uint>();
+      values = new Dictionary<uint, T>();
+      nextIndex = 1;
+    }
+    public Index(IEnumerable<Tuple<uint, T>> values)
+      : this() {
+      foreach (var value in values) {
+        this.indexes.Add(value.Item2, value.Item1);
+        this.values.Add(value.Item1, value.Item2);
+        nextIndex++;
+      }
+    }
+
+    public uint GetIndex(T value) {
+      uint index = 0;
+      indexes.TryGetValue(value, out index);
+      if (index == 0) {
+        index = nextIndex;
+        nextIndex++;
+        indexes.Add(value, index);
+        values.Add(index, value);
+      }
+      return index;
+    }
+    public T GetValue(uint index) {
+      return values[index];
+    }
+    public IEnumerable<Tuple<uint, T>> GetValues() {
+      return values.Select(x => new Tuple<uint, T>(x.Key, x.Value));
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/PersistenceMapper.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/PersistenceMapper.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/PersistenceMapper.cs	(revision 13326)
@@ -0,0 +1,146 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Persistence.Data;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Persistence {
+  public sealed class PersistenceMapper {
+    private ShortIndex<ITransformer> transformers;
+    private Dictionary<Type, TypeInfo> typeInfos;
+    private ShortIndex<Type> types;
+    private Index<string> strings;
+    private Index<PersistenceData> data;
+    private Dictionary<object, uint> dataCache;
+    private Dictionary<uint, object> objectCache;
+
+    public long Nodes { get; private set; }
+
+    public PersistenceMapper() {
+      transformers = new ShortIndex<ITransformer>();
+      typeInfos = new Dictionary<Type, TypeInfo>();
+      types = new ShortIndex<Type>();
+      strings = new Index<string>();
+      data = new Index<PersistenceData>();
+      dataCache = new Dictionary<object, uint>(new ReferenceEqualityComparer<object>());
+      objectCache = new Dictionary<uint, object>();
+
+      Nodes = 0;
+
+      foreach (var transformer in ApplicationManager.Manager.GetInstances<ITransformer>().OrderBy(x => x.Order)) {
+        ushort id = transformers.GetIndex(transformer);
+        transformer.Initialize(id);
+      }
+    }
+
+    public TypeInfo GetTypeInfo(Type type) {
+      TypeInfo typeInfo;
+      typeInfos.TryGetValue(type, out typeInfo);
+      if (typeInfo == null) {
+        var transformer = transformers.GetValues().Select(x => x.Item2).Where(x => x.CanTransformType(type)).FirstOrDefault();
+        typeInfo = new TypeInfo(type, transformer);
+        typeInfos.Add(type, typeInfo);
+      }
+      return typeInfo;
+    }
+    public IEnumerable<TypeInfo> GetTypeInfos() {
+      return typeInfos.Values;
+    }
+    public IEnumerable<Type> GetTypes() {
+      return typeInfos.Values.Select(x => x.Type);
+    }
+
+    public ushort GetTypeId(Type type) {
+      return types.GetIndex(type);
+    }
+    public Type GetType(ushort typeId) {
+      return types.GetValue(typeId);
+    }
+
+    public uint GetStringId(string str) {
+      return strings.GetIndex(str);
+    }
+    public string GetString(uint stringId) {
+      return strings.GetValue(stringId);
+    }
+
+    public void Cache(object o, PersistenceData data) {
+      dataCache.Add(o, this.data.GetIndex(data));
+    }
+    public void Cache(PersistenceData data, object o) {
+      objectCache.Add(this.data.GetIndex(data), o);
+    }
+
+    public uint GetDataId(object o) {
+      if (o == null) return 0;
+      if (dataCache.ContainsKey(o)) return dataCache[o];
+
+      var type = o.GetType();
+      var typeInfo = GetTypeInfo(type);
+      if (typeInfo.Transformer == null) throw new ArgumentException("Cannot serialize object of type " + o.GetType());
+      Nodes++;
+      typeInfo.Used++;
+      return data.GetIndex(typeInfo.Transformer.ToData(o, this));
+    }
+    public object GetObject(uint dataId) {
+      if (dataId == 0) return null;
+      if (objectCache.ContainsKey(dataId)) return objectCache[dataId];
+      var data = this.data.GetValue(dataId);
+      var transformer = transformers.GetValue(data.TransformerId);
+      return transformer.ToObject(data, this);
+    }
+
+    public object CreateInstance(Type type) {
+      return GetTypeInfo(type).GetConstructor()();
+    }
+
+    public static PersistenceMapper mapper;
+    public static PersistenceBundle ToBundle(object o) {
+      mapper = new PersistenceMapper();
+      var bundle = new PersistenceBundle();
+      bundle.RootId = mapper.GetDataId(o);
+      bundle.TransformerGuids = mapper.transformers.GetValues().Select(x => new Tuple<ushort, Guid>(x.Item1, x.Item2.Guid)).ToArray();
+      bundle.TypeNames = mapper.types.GetValues().Select(x => new Tuple<ushort, string>(x.Item1, x.Item2.AssemblyQualifiedName)).ToArray();
+      bundle.Strings = mapper.strings.GetValues().ToArray();
+      bundle.Data = mapper.data.GetValues().ToArray();
+      return bundle;
+    }
+    public static object ToObject(PersistenceBundle bundle) {
+      mapper = new PersistenceMapper();
+      mapper.types = new ShortIndex<Type>(bundle.TypeNames.Select(x => new Tuple<ushort, Type>(x.Item1, Type.GetType(x.Item2, true))));
+      mapper.strings = new Index<string>(bundle.Strings);
+      mapper.data = new Index<PersistenceData>(bundle.Data);
+      mapper.transformers = new ShortIndex<ITransformer>(
+        bundle.TransformerGuids.Select(x => new Tuple<ushort, ITransformer>(
+          x.Item1,
+          mapper.transformers.GetValues().Select(y => y.Item2).Where(y => y.Guid == x.Item2).First())
+        )
+      );
+      foreach (var type in mapper.types.GetValues().Select(x => x.Item2))
+        mapper.typeInfos.Add(type, new TypeInfo(type));
+
+      return mapper.GetObject(bundle.RootId);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ProtoBufSerializer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ProtoBufSerializer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ProtoBufSerializer.cs	(revision 13326)
@@ -0,0 +1,35 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.IO;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  public sealed class ProtoBufSerializer : Serializer {
+    protected override void SerializePersistenceBundle(PersistenceBundle bundle, Stream stream) {
+      ProtoBuf.Serializer.Serialize<PersistenceBundle>(stream, bundle);
+    }
+
+    protected override PersistenceBundle DeserializePersistenceBundle(Stream stream) {
+      return ProtoBuf.Serializer.Deserialize<PersistenceBundle>(stream);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ReferenceEqualityComparer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ReferenceEqualityComparer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ReferenceEqualityComparer.cs	(revision 13326)
@@ -0,0 +1,34 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Collections.Generic;
+
+namespace HeuristicLab.Persistence {
+  public sealed class ReferenceEqualityComparer<T> : IEqualityComparer<T> where T : class {
+    public bool Equals(T x, T y) {
+      return object.ReferenceEquals(x, y);
+    }
+
+    public int GetHashCode(T obj) {
+      return obj == null ? 0 : obj.GetHashCode();
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Serializer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Serializer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Serializer.cs	(revision 13326)
@@ -0,0 +1,67 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.IO;
+using System.IO.Compression;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  public abstract class Serializer : ISerializer {
+    public virtual void Serialize(object o, Stream stream) {
+      SerializePersistenceBundle(PersistenceMapper.ToBundle(o), stream);
+    }
+    public virtual void Serialize(object o, string path) {
+      using (var fileStream = new FileStream(path, FileMode.Create)) {
+        using (var zipStream = new DeflateStream(fileStream, CompressionMode.Compress)) {
+          Serialize(o, zipStream);
+        }
+      }
+    }
+    public virtual byte[] Serialize(object o) {
+      using (var memoryStream = new MemoryStream()) {
+        using (var zipStream = new DeflateStream(memoryStream, CompressionMode.Compress)) {
+          Serialize(o, zipStream);
+        }
+        return memoryStream.ToArray();
+      }
+    }
+    protected abstract void SerializePersistenceBundle(PersistenceBundle bundle, Stream stream);
+
+    public virtual object Deserialize(Stream stream) {
+      return PersistenceMapper.ToObject(DeserializePersistenceBundle(stream));
+    }
+    public virtual object Deserialize(string path) {
+      using (var fileStream = new FileStream(path, FileMode.Open)) {
+        using (var zipStream = new DeflateStream(fileStream, CompressionMode.Decompress)) {
+          return Deserialize(zipStream);
+        }
+      }
+    }
+    public virtual object Deserialize(byte[] data) {
+      using (var memoryStream = new MemoryStream(data)) {
+        using (var zipStream = new DeflateStream(memoryStream, CompressionMode.Decompress)) {
+          return Deserialize(zipStream);
+        }
+      }
+    }
+    protected abstract PersistenceBundle DeserializePersistenceBundle(Stream stream);
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ShortIndex.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ShortIndex.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ShortIndex.cs	(revision 13326)
@@ -0,0 +1,66 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Persistence {
+  [NonDiscoverableType]
+  internal sealed class ShortIndex<T> where T : class {
+    private Dictionary<T, ushort> indexes;
+    private Dictionary<ushort, T> values;
+    private ushort nextIndex;
+
+    public ShortIndex() {
+      indexes = new Dictionary<T, ushort>();
+      values = new Dictionary<ushort, T>();
+      nextIndex = 1;
+    }
+    public ShortIndex(IEnumerable<Tuple<ushort, T>> values)
+      : this() {
+      foreach (var value in values) {
+        this.indexes.Add(value.Item2, value.Item1);
+        this.values.Add(value.Item1, value.Item2);
+        nextIndex++;
+      }
+    }
+
+    public ushort GetIndex(T value) {
+      ushort index = 0;
+      indexes.TryGetValue(value, out index);
+      if (index == 0) {
+        index = nextIndex;
+        nextIndex++;
+        indexes.Add(value, index);
+        values.Add(index, value);
+      }
+      return index;
+    }
+    public T GetValue(ushort index) {
+      return values[index];
+    }
+    public IEnumerable<Tuple<ushort, T>> GetValues() {
+      return values.Select(x => new Tuple<ushort, T>(x.Key, x.Value));
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StorableAttribute.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StorableAttribute.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StorableAttribute.cs	(revision 13326)
@@ -0,0 +1,32 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Reflection;
+
+namespace HeuristicLab.Persistence {
+  [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
+  public sealed class StorableAttribute : Attribute {
+    public static bool IsStorable(MemberInfo memberInfo) {
+      return Attribute.IsDefined(memberInfo, typeof(StorableAttribute), false);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StorableClassAttribute.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StorableClassAttribute.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StorableClassAttribute.cs	(revision 13326)
@@ -0,0 +1,45 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Linq;
+
+namespace HeuristicLab.Persistence {
+  [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
+  public sealed class StorableClassAttribute : Attribute {
+    public Guid Guid { get; private set; }
+    public int Version { get; set; }
+    public bool Released { get; set; }
+
+    public StorableClassAttribute(string guid) {
+      Guid = new Guid(guid);
+      Version = 0;
+      Released = false;
+    }
+
+    public static bool IsStorableClass(Type type) {
+      return Attribute.IsDefined(type, typeof(StorableClassAttribute), false);
+    }
+    public static StorableClassAttribute GetStorableClassAttribute(Type type) {
+      return (StorableClassAttribute)Attribute.GetCustomAttribute(type, typeof(StorableClassAttribute), false);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerAttribute.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerAttribute.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerAttribute.cs	(revision 13326)
@@ -0,0 +1,48 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+
+namespace HeuristicLab.Persistence {
+  [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
+  public sealed class TransformerAttribute : Attribute {
+    public Guid Guid { get; private set; }
+    public ushort Order { get; private set; }
+
+    public TransformerAttribute(string guid, ushort order) {
+      Guid = new Guid(guid);
+      Order = order;
+    }
+
+    public static bool IsTransformer(Type type) {
+      return Attribute.IsDefined(type, typeof(TransformerAttribute), false);
+    }
+    public static TransformerAttribute GetTransformerAttribute(Type type) {
+      return (TransformerAttribute)Attribute.GetCustomAttribute(type, typeof(TransformerAttribute), false);
+    }
+    public static Guid GetGuid(Type type) {
+      return GetTransformerAttribute(type).Guid;
+    }
+    public static ushort GetOrder(Type type) {
+      return GetTransformerAttribute(type).Order;
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerBase.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerBase.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerBase.cs	(revision 13326)
@@ -0,0 +1,45 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  internal abstract class TransformerBase : ITransformer {
+    public Guid Guid { get; private set; }
+    public ushort Id { get; private set; }
+    public ushort Order { get; private set; }
+
+    protected TransformerBase() {
+      Guid = TransformerAttribute.GetGuid(this.GetType());
+      Order = TransformerAttribute.GetOrder(this.GetType());
+      Id = 0;
+    }
+
+    public void Initialize(ushort id) {
+      Id = id;
+    }
+
+    public abstract bool CanTransformType(Type type);
+    public abstract PersistenceData ToData(object o, PersistenceMapper mapper);
+    public abstract object ToObject(PersistenceData data, PersistenceMapper mapper);
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TypeInfo.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TypeInfo.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TypeInfo.cs	(revision 13326)
@@ -0,0 +1,143 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Persistence {
+  public sealed class TypeInfo {
+    private Func<object> constructor;
+
+    public Type Type { get; private set; }
+    public ITransformer Transformer { get; private set; }
+    public StorableClassAttribute StorableClassAttribute { get; private set; }
+    public IEnumerable<ComponentInfo> Fields { get; private set; }
+    public IEnumerable<ComponentInfo> Properties { get; private set; }
+    public IEnumerable<MethodInfo> BeforeSerializationHooks { get; private set; }
+    public IEnumerable<MethodInfo> AfterDeserializationHooks { get; private set; }
+    public long Used { get; set; }
+
+    public TypeInfo(Type type) {
+      constructor = null;
+      Type = type;
+      Fields = Enumerable.Empty<ComponentInfo>();
+      Properties = Enumerable.Empty<ComponentInfo>();
+      BeforeSerializationHooks = Enumerable.Empty<MethodInfo>();
+      AfterDeserializationHooks = Enumerable.Empty<MethodInfo>();
+      Used = 0;
+      Reflect();
+    }
+    public TypeInfo(Type type, ITransformer transformer)
+      : this(type) {
+      Transformer = transformer;
+    }
+
+    private void Reflect() {
+      var type = Type;
+      StorableClassAttribute = StorableClassAttribute.GetStorableClassAttribute(type);
+      if (StorableClassAttribute != null) {
+        // traverse type hierarchy from base type to sub types
+        Stack<Type> types = new Stack<Type>();
+        while (type != null) {
+          types.Push(type);
+          type = type.BaseType;
+        }
+
+        var fields = new List<ComponentInfo>();
+        var properties = new List<ComponentInfo>();
+        var beforeSerializationHooks = new List<MethodInfo>();
+        var afterDeserializationHooks = new List<MethodInfo>();
+        while (types.Count > 0) {
+          type = types.Pop();
+          var fieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic).
+                           Where(x => StorableAttribute.IsStorable(x));
+          foreach (var field in fieldInfos) {
+            var attrib = StorableAttribute.GetStorableAttribute(field);
+            var name = string.IsNullOrEmpty(attrib.Name) ? field.Name : attrib.Name;
+            fields.Add(new ComponentInfo(name, field, attrib, true, true));
+          }
+
+          var propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic).
+                      Where(x => x.GetIndexParameters().Length == 0).  // exclude indexed properties
+                      Where(x => StorableAttribute.IsStorable(x));
+          foreach (var property in propertyInfos) {
+            var attrib = StorableAttribute.GetStorableAttribute(property);
+            var name = string.IsNullOrEmpty(attrib.Name) ? property.Name : attrib.Name;
+            properties.Add(new ComponentInfo(name, property, attrib, property.CanRead, property.CanWrite));
+          }
+
+          var methodInfos = type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic).
+                            Where(x => StorableHookAttribute.IsStorableHook(x)).
+                            Where(x => (x.ReturnType == typeof(void)) && (x.GetParameters().Length == 0));
+          foreach (var method in methodInfos) {
+            foreach (var attrib in StorableHookAttribute.GetStorableHookAttributes(method)) {
+              if (attrib.HookType == HookType.BeforeSerialization)
+                beforeSerializationHooks.Add(method);
+              if (attrib.HookType == HookType.AfterDeserialization)
+                afterDeserializationHooks.Add(method);
+            }
+          }
+        }
+        Fields = fields;
+        Properties = properties;
+        BeforeSerializationHooks = beforeSerializationHooks;
+        AfterDeserializationHooks = afterDeserializationHooks;
+      }
+    }
+
+    public Func<object> GetConstructor() {
+      if (constructor != null) return constructor;
+
+      // get storable constructor
+      var ctor = Type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
+                     .Where(x => StorableConstructorAttribute.IsStorableConstructor(x))
+                     .Where(x => (x.GetParameters().Length == 1) && (x.GetParameters()[0].ParameterType == typeof(bool)))
+                     .FirstOrDefault();
+      if (ctor != null) {
+        DynamicMethod dm = new DynamicMethod("", typeof(object), null, Type, true);
+        ILGenerator ilgen = dm.GetILGenerator();
+        ilgen.Emit(OpCodes.Ldc_I4_1); // load true
+        ilgen.Emit(OpCodes.Newobj, ctor);
+        ilgen.Emit(OpCodes.Ret);
+        constructor = (Func<object>)dm.CreateDelegate(typeof(Func<object>));
+        return constructor;
+      }
+
+      // get default constructor
+      ctor = Type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
+                                 null, Type.EmptyTypes, null);
+      if (ctor != null) {
+        DynamicMethod dm = new DynamicMethod("", typeof(object), null, Type, true);
+        ILGenerator ilgen = dm.GetILGenerator();
+        ilgen.Emit(OpCodes.Newobj, ctor);
+        ilgen.Emit(OpCodes.Ret);
+        constructor = (Func<object>)dm.CreateDelegate(typeof(Func<object>));
+        return constructor;
+      }
+
+      throw new Exception("No storable constructor or parameterless constructor found.");
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/HeuristicLab.Persistence-4.0.csproj
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/HeuristicLab.Persistence-4.0.csproj	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/HeuristicLab.Persistence-4.0.csproj	(revision 13326)
@@ -0,0 +1,84 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{B1663091-8156-4DEB-9E37-5B19810A4644}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HeuristicLab.Persistence</RootNamespace>
+    <AssemblyName>HeuristicLab.Persistence-4.0</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup>
+    <SignAssembly>true</SignAssembly>
+  </PropertyGroup>
+  <PropertyGroup>
+    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Google.ProtocolBuffers-2.4.1.473, Version=2.4.1.473, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\bin\Google.ProtocolBuffers-2.4.1.473.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Data" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Plugin.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Protos\PersistenceMessages.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="HeuristicLab.snk" />
+    <None Include="Plugin.cs.frame" />
+    <None Include="Properties\AssemblyInfo.cs.frame" />
+    <None Include="Protos\PersistenceMessages.proto" />
+    <None Include="Protos\ProcessProtos.cmd" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
+      <Project>{94186a6a-5176-4402-ae83-886557b53cca}</Project>
+      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
+      <Private>False</Private>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
+set ProjectDir=$(ProjectDir)
+set SolutionDir=$(SolutionDir)
+set Outdir=$(Outdir)
+
+call "$(ProjectDir)\Protos\ProcessProtos.cmd"
+call PreBuildEvent.cmd
+</PreBuildEvent>
+  </PropertyGroup>
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/IConverter.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/IConverter.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/IConverter.cs	(revision 13326)
@@ -0,0 +1,25 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+namespace HeuristicLab.Persistence {
+  public interface IConverter {
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ISerializer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ISerializer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ISerializer.cs	(revision 13326)
@@ -0,0 +1,33 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.IO;
+
+namespace HeuristicLab.Persistence {
+  public interface ISerializer {
+    void Serialize(object o, Stream stream);
+    void Serialize(object o, string path);
+    byte[] Serialize(object o);
+    object Deserialize(Stream stream);
+    object Deserialize(string path);
+    object Deserialize(byte[] data);
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ITransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ITransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ITransformer.cs	(revision 13326)
@@ -0,0 +1,37 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  public interface ITransformer {
+    Guid Guid { get; }
+    ushort Id { get; }
+    ushort Order { get; }
+
+    void Initialize(ushort id);
+
+    bool CanTransformType(Type type);
+    PersistenceData ToData(object o, PersistenceMapper mapper);
+    object ToObject(PersistenceData data, PersistenceMapper mapper);
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Plugin.cs.frame
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Plugin.cs.frame	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Plugin.cs.frame	(revision 13326)
@@ -0,0 +1,32 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Persistence {
+  /// <summary>
+  /// Plugin class for HeuristicLab.Persistence plugin.
+  /// </summary>
+  [Plugin("HeuristicLab.Persistence", "4.0.0.$WCREV$")]
+  [PluginFile("HeuristicLab.Persistence-4.0.dll", PluginFileType.Assembly)]
+  [PluginDependency("HeuristicLab.ProtobufCS", "2.4.1.473")]
+  public class HeuristicLabPersistencePlugin : PluginBase { }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Properties/AssemblyInfo.cs.frame
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Properties/AssemblyInfo.cs.frame	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Properties/AssemblyInfo.cs.frame	(revision 13326)
@@ -0,0 +1,54 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("HeuristicLab.Persistence")]
+[assembly: AssemblyDescription("General purpose persistence framework of HeuristicLab.")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HeuristicLab")]
+[assembly: AssemblyCopyright("(c) 2002-2015 HEAL")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("13f6d085-0c47-435d-9fe8-2693126780a2")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+[assembly: AssemblyVersion("4.0.0.0")]
+[assembly: AssemblyFileVersion("4.0.0.$WCREV$")]
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/PersistenceMessages.proto
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/PersistenceMessages.proto	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/PersistenceMessages.proto	(revision 13326)
@@ -0,0 +1,6 @@
+package HeuristicLab.Persistence;
+
+message PersistenceBox {
+  required uint32 TransformerId = 1;
+  required uint32 TypeId = 2;
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/ProcessProtos.cmd
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/ProcessProtos.cmd	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/ProcessProtos.cmd	(revision 13326)
@@ -0,0 +1,4 @@
+for %%i in ("%ProjectDir%Protos\*.proto") do (
+  echo Processing %%i
+  ProtoGen --proto_path="%ProjectDir%\Protos" "%%i" --include_imports -output_directory="%ProjectDir%Protos"
+)
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ArrayTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ArrayTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ArrayTransformer.cs	(revision 13326)
@@ -0,0 +1,180 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Linq;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  internal abstract class GenericArrayTransformer<TSource, TTarget> : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return type.IsArray && (type.GetElementType() == typeof(TSource));
+    }
+
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var arr = (Array)o;
+      var data = new ArrayData<TTarget>(Id);
+      mapper.Cache(o, data);
+      var elementType = arr.GetType().GetElementType();
+      data.ElementTypeId = mapper.GetTypeId(elementType);
+
+      if (arr.Rank == 1) {
+        data.Values = GetTargets((TSource[])o, mapper);
+        //data.Values = GetTargets(Array.ConvertAll(arr, x => (object)x), mapper);
+        //data.Values = GetTargets(arr.Cast<TSource>().ToArray(), mapper);
+        return data;
+      } else {
+        data.Lengths = new int[arr.Rank];
+        int[] positions = new int[arr.Rank];
+        for (int i = 0; i < arr.Rank; i++) {
+          data.Lengths[i] = arr.GetLength(i);
+          positions[i] = 0;
+        }
+
+        data.Values = new TTarget[arr.Length];
+        for (int i = 0; i < data.Values.Length; i++) {
+          data.Values[i] = GetTarget((TSource)arr.GetValue(positions), mapper);
+          positions[0] += 1;
+          for (int j = 0; j < arr.Rank - 1; j++) {
+            if (positions[j] >= data.Lengths[j]) {
+              positions[j] = 0;
+              positions[j + 1] += 1;
+            } else {
+              break;
+            }
+          }
+        }
+        return data;
+      }
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var arrayData = (ArrayData<TTarget>)data;
+      var elementType = mapper.GetType(arrayData.ElementTypeId);
+      if (arrayData.Lengths.Length <= 1) {  // single dimensional
+        var o = GetSources(arrayData.Values, mapper);
+        mapper.Cache(data, o);
+        return o;
+      } else {
+        var o = Array.CreateInstance(elementType, arrayData.Lengths);
+        mapper.Cache(data, o);
+
+        int[] positions = new int[arrayData.Lengths.Length];
+        positions.Initialize();
+        for (int i = 0; i < arrayData.Values.Length; i++) {
+          o.SetValue(GetSource(arrayData.Values[i], mapper), positions);
+          positions[0] += 1;
+          for (int j = 0; j < o.Rank - 1; j++) {
+            if (positions[j] >= arrayData.Lengths[j]) {
+              positions[j] = 0;
+              positions[j + 1] += 1;
+            } else {
+              break;
+            }
+          }
+        }
+        return o;
+      }
+    }
+
+    protected abstract TTarget[] GetTargets(TSource[] sources, PersistenceMapper mapper);
+    protected abstract TSource[] GetSources(TTarget[] targets, PersistenceMapper mapper);
+    protected abstract TTarget GetTarget(TSource source, PersistenceMapper mapper);
+    protected abstract TSource GetSource(TTarget target, PersistenceMapper mapper);
+  }
+
+  internal abstract class PrimitiveArrayTransformer<T> : GenericArrayTransformer<T, T> {
+    protected override T[] GetTargets(T[] sources, PersistenceMapper mapper) {
+      return sources;
+    }
+    protected override T[] GetSources(T[] targets, PersistenceMapper mapper) {
+      return targets;
+    }
+    protected override T GetTarget(T source, PersistenceMapper mapper) {
+      return source;
+    }
+    protected override T GetSource(T target, PersistenceMapper mapper) {
+      return target;
+    }
+  }
+
+  [Transformer("F25A73B2-6B67-4493-BD59-B836AF4455D1", 300)]
+  internal sealed class BoolArrayTransformer : PrimitiveArrayTransformer<bool> { }
+
+  [Transformer("FF89F6D1-CDE3-498E-9166-F70AC6EB01F1", 301)]
+  internal sealed class ByteArrayTransformer : PrimitiveArrayTransformer<byte> { }
+
+  [Transformer("B49B3F2D-2E97-4BAB-8705-8D29DA707C6A", 302)]
+  internal sealed class SByteArrayTransformer : PrimitiveArrayTransformer<sbyte> { }
+
+  [Transformer("2811FDD4-6800-4CBA-86D7-9071ED5775ED", 303)]
+  internal sealed class ShortArrayTransformer : PrimitiveArrayTransformer<short> { }
+
+  [Transformer("1AAC2625-356C-40BC-8CB4-15CB3D047EB8", 304)]
+  internal sealed class UShortArrayTransformer : PrimitiveArrayTransformer<ushort> { }
+
+  [Transformer("12F19098-5D49-4C23-8897-69087F1C146D", 305)]
+  internal sealed class CharArrayTransformer : PrimitiveArrayTransformer<char> { }
+
+  [Transformer("5F6DC3BC-4433-4AE9-A636-4BD126F7DACD", 306)]
+  internal sealed class IntArrayTransformer : PrimitiveArrayTransformer<int> { }
+
+  [Transformer("3F10274F-D350-4C82-89EA-A5EB36D4EFCC", 307)]
+  internal sealed class UIntArrayTransformer : PrimitiveArrayTransformer<uint> { }
+
+  [Transformer("E9D550E2-57F7-47F3-803D-37A619DA1A5C", 308)]
+  internal sealed class LongArrayTransformer : PrimitiveArrayTransformer<long> { }
+
+  [Transformer("C02A205B-2176-4282-AC2B-ADEF96DDBE24", 309)]
+  internal sealed class ULongArrayTransformer : PrimitiveArrayTransformer<ulong> { }
+
+  [Transformer("3C4590D9-C76E-4AFB-98FD-E50D3D051648", 310)]
+  internal sealed class FloatArrayTransformer : PrimitiveArrayTransformer<float> { }
+
+  [Transformer("FB98C399-9323-4470-9A85-9186C2B2D5D4", 311)]
+  internal sealed class DoubleArrayTransformer : PrimitiveArrayTransformer<double> { }
+
+  [Transformer("9E68A52B-2EC8-447E-B45B-D382A16283D4", 312)]
+  internal sealed class DecimalArrayTransformer : PrimitiveArrayTransformer<decimal> { }
+
+  [Transformer("68332513-9CF1-47FA-A093-6DDB663186EC", 313)]
+  internal sealed class StringArrayTransformer : PrimitiveArrayTransformer<string> { }
+
+  [Transformer("C83F0B5A-68D8-4271-81F9-FF259FC6F126", 400)]
+  internal sealed class ArrayTransformer : GenericArrayTransformer<object, uint> {
+    public override bool CanTransformType(Type type) {
+      return type.IsArray;
+    }
+
+    protected override uint[] GetTargets(object[] sources, PersistenceMapper mapper) {
+      return sources.Select(x => mapper.GetDataId(x)).ToArray();
+    }
+    protected override object[] GetSources(uint[] targets, PersistenceMapper mapper) {
+      return targets.Select(x => mapper.GetObject(x)).ToArray();
+    }
+    protected override uint GetTarget(object source, PersistenceMapper mapper) {
+      return mapper.GetDataId(source);
+    }
+    protected override object GetSource(uint target, PersistenceMapper mapper) {
+      return mapper.GetObject(target);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/DictionaryTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/DictionaryTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/DictionaryTransformer.cs	(revision 13326)
@@ -0,0 +1,102 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  internal abstract class GenericDictionaryTransformer : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Dictionary<,>));
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var type = o.GetType();
+      var data = new DictionaryData(Id);
+      mapper.Cache(o, data);
+      data.TypeId = mapper.GetTypeId(type);
+
+      var dict = (IDictionary)o;
+      data.KeyIds = new uint[dict.Count];
+      data.ValueIds = new uint[dict.Count];
+      int i = 0;
+      foreach (DictionaryEntry element in dict) {
+        data.KeyIds[i] = GetTargetKey(element.Key, mapper);
+        data.ValueIds[i] = GetTargetValue(element.Value, mapper);
+        i++;
+      }
+      data.ComparerId = mapper.GetDataId(type.GetProperty("Comparer").GetValue(o, null));
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var composite = (DictionaryData)data;
+      var type = mapper.GetType(composite.TypeId);
+      var o = (IDictionary)Activator.CreateInstance(type, mapper.GetObject(composite.ComparerId));
+      mapper.Cache(data, o);
+      for (int i = 0; i < composite.KeyIds.Length; i++) {
+        o.Add(GetSourceKey(composite.KeyIds[i], mapper), GetSourceValue(composite.ValueIds[i], mapper));
+      }
+      return o;
+    }
+
+    protected abstract uint GetTargetKey(object sourceKey, PersistenceMapper mapper);
+    protected abstract uint GetTargetValue(object sourceValue, PersistenceMapper mapper);
+    protected abstract object GetSourceKey(uint targetKey, PersistenceMapper mapper);
+    protected abstract object GetSourceValue(uint targetValue, PersistenceMapper mapper);
+  }
+
+  [Transformer("AC7F11D4-3390-4DE2-B6FC-1705DAB627F6", 403)]
+  internal sealed class StringDictionaryTransformer : GenericDictionaryTransformer {
+    public override bool CanTransformType(Type type) {
+      return base.CanTransformType(type) && (type.GetGenericArguments()[0] == typeof(string));
+    }
+    protected override uint GetTargetKey(object sourceKey, PersistenceMapper mapper) {
+      return mapper.GetStringId((string)sourceKey);
+    }
+    protected override uint GetTargetValue(object sourceValue, PersistenceMapper mapper) {
+      return mapper.GetDataId(sourceValue);
+    }
+    protected override object GetSourceKey(uint targetKey, PersistenceMapper mapper) {
+      return mapper.GetString(targetKey);
+    }
+    protected override object GetSourceValue(uint targetValue, PersistenceMapper mapper) {
+      return mapper.GetObject(targetValue);
+    }
+  }
+
+  [Transformer("D1EF55D6-843A-42AF-8EBB-49566981C943", 404)]
+  internal sealed class DictionaryTransformer : GenericDictionaryTransformer {
+    protected override uint GetTargetKey(object sourceKey, PersistenceMapper mapper) {
+      return mapper.GetDataId(sourceKey);
+    }
+    protected override uint GetTargetValue(object sourceValue, PersistenceMapper mapper) {
+      return mapper.GetDataId(sourceValue);
+    }
+    protected override object GetSourceKey(uint targetKey, PersistenceMapper mapper) {
+      return mapper.GetObject(targetKey);
+    }
+    protected override object GetSourceValue(uint targetValue, PersistenceMapper mapper) {
+      return mapper.GetObject(targetValue);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/EmptyTypeTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/EmptyTypeTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/EmptyTypeTransformer.cs	(revision 13326)
@@ -0,0 +1,53 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Reflection;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  [Transformer("A2A2F675-012B-4D50-93A5-B8E728D9809C", 999)]
+  internal sealed class EmptyTypeTransformer : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      while (type != null) {
+        if (type.IsArray) return false;  // arrays are no empty types but contain no fields
+        var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
+        if (fields.Length != 0) return false;
+        type = type.BaseType;
+      }
+      return true;
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var type = o.GetType();
+      var data = new ValueData<ushort>(Id);
+      mapper.Cache(o, data);
+      data.Value = mapper.GetTypeId(type);
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var primitive = (ValueData<ushort>)data;
+      var o = Activator.CreateInstance(mapper.GetType(primitive.Value));
+      mapper.Cache(data, o);
+      return o;
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/KeyValuePairTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/KeyValuePairTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/KeyValuePairTransformer.cs	(revision 13326)
@@ -0,0 +1,49 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  [Transformer("97B5CFC8-CDFA-4EB5-B4CD-5B3CFA5CD844", 219)]
+  internal sealed class KeyValuePairTransformer : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>));
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var data = new ArrayData<uint>(Id);
+      var type = o.GetType();
+      data.TypeId = mapper.GetTypeId(type);
+      data.Values = new uint[2];
+      data.Values[0] = mapper.GetDataId(type.GetProperty("Key").GetValue(o, null));
+      data.Values[1] = mapper.GetDataId(type.GetProperty("Value").GetValue(o, null));
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var composite = (ArrayData<uint>)data;
+      var key = mapper.GetObject(composite.Values[0]);
+      var value = mapper.GetObject(composite.Values[1]);
+      return Activator.CreateInstance(mapper.GetType(composite.TypeId), key, value);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ListTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ListTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ListTransformer.cs	(revision 13326)
@@ -0,0 +1,138 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  internal abstract class GenericListTransformer<TSource, TTarget> : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return type == typeof(List<TSource>);
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var data = new ArrayData<TTarget>(Id);
+      mapper.Cache(o, data);
+      data.TypeId = mapper.GetTypeId(o.GetType());
+
+      var enumerable = (IEnumerable<TSource>)o;
+      var componentIds = new List<TTarget>();
+      foreach (var component in enumerable) {
+        componentIds.Add(GetTarget(component, mapper));
+      }
+      data.Values = componentIds.ToArray();
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var collection = (ArrayData<TTarget>)data;
+      var type = mapper.GetType(collection.TypeId);
+
+      var o = Activator.CreateInstance(type, true);
+      mapper.Cache(data, o);
+      dynamic list = o;
+      foreach (var component in collection.Values) {
+        list.Add(GetSource(component, mapper));
+      }
+      return o;
+    }
+
+    protected abstract TTarget GetTarget(TSource source, PersistenceMapper mapper);
+    protected abstract TSource GetSource(TTarget target, PersistenceMapper mapper);
+  }
+
+  internal abstract class PrimitiveListTransformer<T> : GenericListTransformer<T, T> {
+    protected override T GetTarget(T source, PersistenceMapper mapper) {
+      return source;
+    }
+    protected override T GetSource(T target, PersistenceMapper mapper) {
+      return target;
+    }
+  }
+
+  [Transformer("C34E96D4-8890-4AA6-BF40-D8A439ABBF2E", 401)]
+  internal sealed class DoubleListTransformer : PrimitiveListTransformer<double> { }
+
+  [Transformer("B551DCEF-64FA-4AA9-87EE-0C49F44B6903", 402)]
+  internal sealed class StringListTransformer : PrimitiveListTransformer<string> { }
+
+  [Transformer("16A662E1-BB7A-4A0B-B646-6B8B6C8B89F9", 407)]
+  internal sealed class ListTransformer : GenericListTransformer<object, uint> {
+    public override bool CanTransformType(Type type) {
+      return type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(List<>));
+    }
+
+    protected override uint GetTarget(object source, PersistenceMapper mapper) {
+      return mapper.GetDataId(source);
+    }
+    protected override object GetSource(uint target, PersistenceMapper mapper) {
+      return mapper.GetObject(target);
+    }
+  }
+
+  [Transformer("DEA9A14A-034C-46B6-BD96-676B90C21159", 408)]
+  internal sealed class HashSetTransformer : GenericListTransformer<object, uint> {
+    public override bool CanTransformType(Type type) {
+      return type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(HashSet<>));
+    }
+
+    protected override uint GetTarget(object source, PersistenceMapper mapper) {
+      return mapper.GetDataId(source);
+    }
+    protected override object GetSource(uint target, PersistenceMapper mapper) {
+      return mapper.GetObject(target);
+    }
+  }
+}
+
+
+//using System;
+//using System.Collections.Generic;
+//using HeuristicLab.Persistence.Data;
+
+//namespace HeuristicLab.Persistence {
+//  internal abstract class ListTransformer<T> : TransformerBase {
+//    public override bool CanTransformType(Type type) {
+//      return type == typeof(List<T>);
+//    }
+//    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+//      var list = (List<T>)o;
+//      var data = new ArrayData<T>(Id);
+//      mapper.Cache(o, data);
+//      data.Values = list.ToArray();
+//      return data;
+//    }
+
+//    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+//      var array = (ArrayData<T>)data;
+//      var o = new List<T>();
+//      mapper.Cache(data, o);
+//      o.AddRange(array.Values);
+//      return o;
+//    }
+//  }
+
+//  [Transformer("C34E96D4-8890-4AA6-BF40-D8A439ABBF2E", 401)]
+//  internal sealed class DoubleListTransformer : ListTransformer<double> { }
+
+//  [Transformer("B551DCEF-64FA-4AA9-87EE-0C49F44B6903", 402)]
+//  internal sealed class StringListTransformer : ListTransformer<string> { }
+//}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/PointTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/PointTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/PointTransformer.cs	(revision 13326)
@@ -0,0 +1,47 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Drawing;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  [Transformer("2E6D4A40-B4BE-425F-8E35-2D7C00054639", 220)]
+  internal sealed class PointTransformer : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return type == typeof(Point);
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var point = (Point)o;
+      var data = new ArrayData<int>(Id);
+      data.TypeId = mapper.GetTypeId(o.GetType());
+      data.Values = new int[2];
+      data.Values[0] = point.X;
+      data.Values[1] = point.Y;
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var pointData = (ArrayData<int>)data;
+      return new Point(pointData.Values[0], pointData.Values[1]);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StackTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StackTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StackTransformer.cs	(revision 13326)
@@ -0,0 +1,89 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  internal abstract class GenericStackTransformer<TSource, TTarget> : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return type == typeof(Stack<TSource>);
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var data = new ArrayData<TTarget>(Id);
+      mapper.Cache(o, data);
+      data.TypeId = mapper.GetTypeId(o.GetType());
+
+      var enumerable = (IEnumerable<TSource>)o;
+      var componentIds = new List<TTarget>();
+      foreach (var component in enumerable) {
+        componentIds.Add(GetTarget(component, mapper));
+      }
+      componentIds.Reverse();
+      data.Values = componentIds.ToArray();
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var collection = (ArrayData<TTarget>)data;
+      var type = mapper.GetType(collection.TypeId);
+
+      var o = Activator.CreateInstance(type, true);
+      mapper.Cache(data, o);
+      dynamic stack = o;
+      foreach (var component in collection.Values) {
+        stack.Push(GetSource(component, mapper));
+      }
+      return o;
+    }
+
+    protected abstract TTarget GetTarget(TSource source, PersistenceMapper mapper);
+    protected abstract TSource GetSource(TTarget target, PersistenceMapper mapper);
+  }
+
+  internal abstract class PrimitiveStackTransformer<T> : GenericStackTransformer<T, T> {
+    protected override T GetTarget(T source, PersistenceMapper mapper) {
+      return source;
+    }
+    protected override T GetSource(T target, PersistenceMapper mapper) {
+      return target;
+    }
+  }
+
+  [Transformer("305FE51F-CE6A-43A7-A0FC-CCFFC1378680", 405)]
+  internal sealed class DoubleStackTransformer : PrimitiveStackTransformer<double> { }
+
+  [Transformer("E84A21DF-BDAF-4A24-9EF6-934ACDB82423", 406)]
+  internal sealed class StackTransformer : GenericStackTransformer<object, uint> {
+    public override bool CanTransformType(Type type) {
+      return type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Stack<>));
+    }
+
+    protected override uint GetTarget(object source, PersistenceMapper mapper) {
+      return mapper.GetDataId(source);
+    }
+    protected override object GetSource(uint target, PersistenceMapper mapper) {
+      return mapper.GetObject(target);
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StorableClassTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StorableClassTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StorableClassTransformer.cs	(revision 13326)
@@ -0,0 +1,96 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using HeuristicLab.Persistence.Data;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Persistence {
+  [Transformer("78556C88-0FEE-4602-95C7-A469B2DDB468", 100)]
+  internal sealed class StorableClassTransformer : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return StorableClassAttribute.IsStorableClass(type);
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      var type = o.GetType();
+      var typeInfo = mapper.GetTypeInfo(type);
+      var attribute = typeInfo.StorableClassAttribute;
+      var data = new CompositeData(Id);
+      mapper.Cache(o, data);
+      data.TypeId = mapper.GetTypeId(type);
+      // data.GuidId = attribute.Guid;
+      // data.Version = attribute.Version;
+
+      var emptyArgs = new object[0];
+      foreach (var hook in typeInfo.BeforeSerializationHooks) {
+        hook.Invoke(o, emptyArgs);
+      }
+      var components = new Dictionary<uint, uint>();
+      foreach (var componentInfo in typeInfo.Fields) {
+        var field = (FieldInfo)componentInfo.MemberInfo;
+        var component = mapper.GetDataId(field.GetValue(o));
+        components.Add(mapper.GetStringId(componentInfo.Name), component);
+      }
+      foreach (var componentInfo in typeInfo.Properties.Where(x => x.Readable)) {
+        var property = (PropertyInfo)componentInfo.MemberInfo;
+        var component = mapper.GetDataId(property.GetValue(o, null));
+        components.Add(mapper.GetStringId(componentInfo.Name), component);
+      }
+      data.ComponentNameIds = components.Keys.ToArray();
+      data.ComponentIds = components.Values.ToArray();
+      return data;
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      var composite = (CompositeData)data;
+      var type = mapper.GetType(composite.TypeId);
+      var typeInfo = mapper.GetTypeInfo(type);
+      var o = mapper.CreateInstance(type);
+      mapper.Cache(data, o);
+
+      var components = new Dictionary<uint, uint>();
+      for (int i = 0; i < composite.ComponentNameIds.Length; i++) {
+        components.Add(composite.ComponentNameIds[i], composite.ComponentIds[i]);
+      }
+
+      foreach (var componentInfo in typeInfo.Fields) {
+        var field = (FieldInfo)componentInfo.MemberInfo;
+        uint componentId;
+        components.TryGetValue(mapper.GetStringId(componentInfo.Name), out componentId);
+        field.SetValue(o, componentId != 0 ? mapper.GetObject(componentId) : componentInfo.StorableAttribute.DefaultValue);
+      }
+      foreach (var componentInfo in typeInfo.Properties.Where(x => x.Writeable)) {
+        var property = (PropertyInfo)componentInfo.MemberInfo;
+        uint componentId;
+        components.TryGetValue(mapper.GetStringId(componentInfo.Name), out componentId);
+        property.SetValue(o, componentId != 0 ? mapper.GetObject(componentId) : componentInfo.StorableAttribute.DefaultValue, null);
+      }
+      var emptyArgs = new object[0];
+      foreach (var hook in typeInfo.AfterDeserializationHooks) {
+        hook.Invoke(o, emptyArgs);
+      }
+      return o;
+    }
+  }
+}
Index: branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ValueTransformer.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ValueTransformer.cs	(revision 13326)
+++ branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/ValueTransformer.cs	(revision 13326)
@@ -0,0 +1,173 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Drawing;
+using HeuristicLab.Persistence.Data;
+
+namespace HeuristicLab.Persistence {
+  internal abstract class ValueTransformer<TSource, TTarget> : TransformerBase {
+    public override bool CanTransformType(Type type) {
+      return typeof(TSource) == type;
+    }
+    public override PersistenceData ToData(object o, PersistenceMapper mapper) {
+      return GetTarget((TSource)o, mapper);
+    }
+
+    public override object ToObject(PersistenceData data, PersistenceMapper mapper) {
+      return GetSource((ValueData<TTarget>)data, mapper);
+    }
+
+    protected abstract ValueData<TTarget> GetTarget(TSource source, PersistenceMapper mapper);
+    protected abstract TSource GetSource(ValueData<TTarget> target, PersistenceMapper mapper);
+  }
+
+  internal abstract class ValueTypeTransformer<T> : ValueTransformer<T, T> {
+    protected override ValueData<T> GetTarget(T source, PersistenceMapper mapper) {
+      var data = new ValueData<T>(Id);
+      data.TypeId = mapper.GetTypeId(source.GetType());
+      data.Value = source;
+      return data;
+    }
+    protected override T GetSource(ValueData<T> target, PersistenceMapper mapper) {
+      return target.Value;
+    }
+  }
+
+  #region Primitive Value Types
+  [Transformer("9FA1C6A8-517E-4623-AC1B-7E9AEF6ED13D", 200)]
+  internal sealed class BoolTransformer : ValueTypeTransformer<bool> { }
+
+  [Transformer("059633E9-12CB-43EC-8544-57746536E281", 201)]
+  internal sealed class ByteTransformer : ValueTypeTransformer<byte> { }
+
+  [Transformer("5DC2F3AC-0852-4B57-A861-D29CC814A94C", 202)]
+  internal sealed class SByteTransformer : ValueTypeTransformer<sbyte> { }
+
+  [Transformer("B862E642-A94A-4870-8065-06126A35A9E1", 203)]
+  internal sealed class ShortTransformer : ValueTypeTransformer<short> { }
+
+  [Transformer("D1D3062D-F1BB-4189-AE50-D6986E1DEB4E", 204)]
+  internal sealed class UShortTransformer : ValueTypeTransformer<ushort> { }
+
+  [Transformer("6C444645-3062-4D15-AD01-E6E1B0692A2B", 205)]
+  internal sealed class CharTransformer : ValueTypeTransformer<char> { }
+
+  [Transformer("649E73B2-EFA6-4E01-BCB4-4B29D652C9CB", 206)]
+  internal sealed class IntTransformer : ValueTypeTransformer<int> { }
+
+  [Transformer("BCF25010-81A2-49BC-88CC-407D3F393D5B", 207)]
+  internal sealed class UIntTransformer : ValueTypeTransformer<uint> { }
+
+  [Transformer("B6F6ACAE-755C-47EE-B8BF-7CDECBE19C30", 208)]
+  internal sealed class LongTransformer : ValueTypeTransformer<long> { }
+
+  [Transformer("82333ACA-F041-44E0-B365-27C399594BA7", 209)]
+  internal sealed class ULongTransformer : ValueTypeTransformer<ulong> { }
+
+  [Transformer("8FE91ECF-2261-4934-BECD-C38923B7A703", 210)]
+  internal sealed class FloatTransformer : ValueTypeTransformer<float> { }
+
+  [Transformer("070D23EA-7F38-46B7-A667-219BEF914E49", 211)]
+  internal sealed class DoubleTransformer : ValueTypeTransformer<double> { }
+
+  [Transformer("80368686-0531-4D52-B550-E772B8842E6D", 212)]
+  internal sealed class DecimalTransformer : ValueTypeTransformer<decimal> { }
+
+  [Transformer("BA55C7A6-C91E-4351-A889-E4A7E647F16D", 213)]
+  internal sealed class DateTimeTransformer : ValueTypeTransformer<DateTime> { }
+
+  [Transformer("0C91441B-2D97-432B-B493-D6EC483FC5AD", 214)]
+  internal sealed class TimeSpanTransformer : ValueTypeTransformer<TimeSpan> { }
+  #endregion
+
+  #region String
+  [Transformer("E75A594C-0034-4DAB-B28E-8F84F9F6DE8D", 215)]
+  internal sealed class StringTransformer : ValueTransformer<string, uint> {
+    protected override ValueData<uint> GetTarget(string source, PersistenceMapper mapper) {
+      var data = new ValueData<uint>(Id);
+      mapper.Cache(source, data);
+      data.TypeId = mapper.GetTypeId(source.GetType());
+      data.Value = mapper.GetStringId(source);
+      return data;
+    }
+    protected override string GetSource(ValueData<uint> target, PersistenceMapper mapper) {
+      var source = mapper.GetString(target.Value);
+      mapper.Cache(target, source);
+      return source;
+    }
+  }
+  #endregion
+
+  #region Enum
+  [Transformer("93FF076B-BC4B-4C39-8C40-15E004468C98", 216)]
+  internal sealed class EnumTransformer : ValueTransformer<object, uint> {
+    public override bool CanTransformType(Type type) {
+      return typeof(Enum).IsAssignableFrom(type);
+    }
+    protected override ValueData<uint> GetTarget(object source, PersistenceMapper mapper) {
+      var type = source.GetType();
+      var data = new ValueData<uint>(Id);
+      data.TypeId = mapper.GetTypeId(type);
+      data.Value = mapper.GetStringId(Enum.Format(type, source, "G"));
+      return data;
+    }
+    protected override object GetSource(ValueData<uint> target, PersistenceMapper mapper) {
+      return Enum.Parse(mapper.GetType(target.TypeId), mapper.GetString(target.Value));
+    }
+  }
+  #endregion
+
+  #region Color
+  [Transformer("0B540EAC-79AB-40CF-8277-D2C81135FEB6", 217)]
+  internal sealed class ColorTransformer : ValueTransformer<Color, int> {
+    protected override ValueData<int> GetTarget(Color source, PersistenceMapper mapper) {
+      var data = new ValueData<int>(Id);
+      data.TypeId = mapper.GetTypeId(source.GetType());
+      data.Value = source.ToArgb();
+      return data;
+    }
+    protected override Color GetSource(ValueData<int> target, PersistenceMapper mapper) {
+      return Color.FromArgb(target.Value);
+    }
+  }
+  #endregion
+
+  #region Type
+  [Transformer("8D17FD28-383B-44E9-9BBF-B19D351C5E38", 218)]
+  internal sealed class TypeTransformer : ValueTransformer<Type, ushort> {
+    public override bool CanTransformType(Type type) {
+      return typeof(Type).IsAssignableFrom(type);
+    }
+    protected override ValueData<ushort> GetTarget(Type source, PersistenceMapper mapper) {
+      var data = new ValueData<ushort>(Id);
+      mapper.Cache(source, data);
+      data.Value = mapper.GetTypeId(source);
+      return data;
+    }
+    protected override Type GetSource(ValueData<ushort> target, PersistenceMapper mapper) {
+      var type = mapper.GetType(target.Value);
+      mapper.Cache(target, type);
+      return type;
+    }
+  }
+  #endregion
+}
