Index: /branches/New Persistence Exploration/Persistence/Persistence/CompoundSerializers.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/CompoundSerializers.cs	(revision 1322)
+++ /branches/New Persistence Exploration/Persistence/Persistence/CompoundSerializers.cs	(revision 1323)
@@ -30,5 +30,5 @@
       object instance = Activator.CreateInstance(t);
       foreach (object o in objects) {
-        t.GetMethod("Add").Invoke(instance, new object[] { o });
+        t.GetMethod("Add").Invoke(instance, new[] { o });
       }
       return instance;
Index: anches/New Persistence Exploration/Persistence/Persistence/NewSerializationTest.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/NewSerializationTest.cs	(revision 1322)
+++ 	(revision )
@@ -1,258 +1,0 @@
-﻿using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Collections;
-using System.IO;
-
-namespace Persistence.Test {
-
-  public class Root {
-    [Storable]
-    public int[] i = new int[] { 3, 4, 5, 6 };
-    [Storable]
-    public string s;
-    [Storable]
-    public ArrayList intArray = new ArrayList(new int[] { 1, 2, 3 });
-    [Storable]
-    public List<int> intList = new List<int>(new int[] { 321, 312, 321 });
-    [Storable]
-    public Custom c;
-    [Storable]
-    public List<Root> selfReferences;
-    [Storable]
-    public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
-    [Storable]
-    public bool boolean = true;
-    [Storable]
-    public DateTime dateTime = new DateTime();
-    [Storable]
-    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
-    [Storable]
-    public Dictionary<string, int> dict = new Dictionary<string, int>();
-  }
-
-  public class Custom {
-    [Storable]
-    public int i;
-    [Storable]
-    public Root r;
-    [Storable]
-    public string name = "Serial";
-  }
-
-  public class CloneableRoot {
-    public int[] i = new int[] { 3, 4, 5, 6 };
-    public string s;
-    public ArrayList intArray = new ArrayList(new int[] { 1, 2, 3 });
-    public List<int> intList = new List<int>(new int[] { 321, 312, 321 });
-    public CloneableCustom c;
-    public List<CloneableRoot> selfReferences;
-    public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
-    public bool boolean = true;
-    public DateTime dateTime = new DateTime();
-    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
-    public Dictionary<string, int> dict = new Dictionary<string, int>();    
-    public object Clone(Dictionary<object, object> twins) {
-      if (twins.ContainsKey(this))
-        return twins[this];      
-      CloneableRoot cr = new CloneableRoot();
-      twins.Add(this, cr);
-      cr.i = this.i;
-      cr.s = this.s;
-      cr.intArray = new ArrayList(this.intArray);
-      cr.intList = new List<int>(this.intList);
-      cr.c = (CloneableCustom)c.Clone(twins);
-      cr.selfReferences = new List<CloneableRoot>();
-      for (int i = 0; i < this.selfReferences.Count; i++) {
-        cr.selfReferences.Add(this);
-      }
-      cr.multiDimArray = (double[,])this.multiDimArray.Clone();
-      cr.dateTime = new DateTime(this.dateTime.Ticks);
-      cr.kvp = new KeyValuePair<string, int>(this.kvp.Key, this.kvp.Value);
-      cr.dict = new Dictionary<string, int>(this.dict);
-      return cr;
-    }    
-  }
-
-  public class CloneableCustom {    
-    public int i;    
-    public CloneableRoot r;    
-    public string name = "Serial";
-    public object Clone(Dictionary<object, object> twins) {
-      if (twins.ContainsKey(this))
-        return twins[this];
-      CloneableCustom cc = new CloneableCustom();
-      twins.Add(this, cc);
-      cc.i = this.i;
-      cc.r = (CloneableRoot)this.r.Clone(twins);
-      cc.name = this.name;
-      return cc;
-    }
-  }
-
-  public class Manager {
-
-    private DateTime lastLoadTime;
-    [Storable]
-    private DateTime lastLoadTimePersistence {
-      get { return lastLoadTime; }
-      set { this.lastLoadTime = DateTime.Now; }
-    }
-    [Storable]
-    private Nullable<double> dbl = null;
-  }
-
-  public class StorableObject {
-
-    [Storable]
-    Dictionary<int, string> dict;
-
-    public void Init() {
-      this.dict = new Dictionary<int, string>();
-      for (int i = 0; i < 1000000; i++) {
-        dict.Add(i, i.ToString());
-      }
-    }
-  }
-
-  public class CloneableObject : ICloneable {
-
-    Dictionary<int, string> dict;
-
-    public void Init() {
-      this.dict = new Dictionary<int, string>();
-      for (int i = 0; i < 1000000; i++) {
-        dict.Add(i, i.ToString());
-      }
-    }
-    public object Clone() {
-      CloneableObject clone = new CloneableObject();
-      clone.dict = new Dictionary<int, string>(this.dict);
-      return clone;
-    }
-  }  
-
-  public class NewSerializationTest {
-
-    public static void Test1() {
-      Root r = new Root();
-      r.selfReferences = new List<Root>();
-      r.selfReferences.Add(r);
-      r.selfReferences.Add(r);
-      r.c = new Custom();
-      r.c.r = r;
-      r.dict.Add("one", 1);
-      r.dict.Add("two", 2);
-      r.dict.Add("three", 3);
-      Serializer s = new Serializer(r);        
-      Persistence.XmlFormatter xmlFormatter = new Persistence.XmlFormatter();
-      StreamWriter writer = new StreamWriter("test.xml");
-      foreach (ISerializationToken token in s) {
-        string line = xmlFormatter.Format(token);
-        writer.Write(line);
-        Console.Out.Write(line);
-      }
-      writer.Close();
-      XmlParser parser = new XmlParser(new StreamReader("test.xml"));
-      DeSerializer deSerializer = new DeSerializer();        
-      object o = deSerializer.DeSerialize(parser);
-      Root t = CloningFactory.DefaultClone(r);
-      Console.Out.WriteLine(Util.AutoFormat(o, true));      
-    }
-
-    public static void Test2() {
-      Manager m = new Manager();      
-      Serializer s = new Serializer(m);
-      Persistence.XmlFormatter xmlFormatter = new Persistence.XmlFormatter();
-      StreamWriter writer = new StreamWriter("test2.xml");
-      foreach (ISerializationToken token in s) {
-        string line = xmlFormatter.Format(token);
-        writer.Write(line);
-        Console.Out.Write(line);
-      }
-      writer.Close();
-      XmlParser parser = new XmlParser(new StreamReader("test2.xml"));
-      DeSerializer deSerializer = new DeSerializer();
-      object o = deSerializer.DeSerialize(parser);
-      Manager n = CloningFactory.DefaultClone(m);
-      Console.Out.WriteLine(Util.AutoFormat(o, true));      
-    }
-
-    public static void SpeedTest() {
-      StorableObject storable = new StorableObject();
-      CloneableObject cloneable = new CloneableObject();
-      Console.Write("initializing...");
-      storable.Init();
-      cloneable.Init();
-      Console.WriteLine("done");
-      List<StorableObject> storableClones = new List<StorableObject>();
-      List<CloneableObject> clonableClones = new List<CloneableObject>();
-      CloningFactory cloningFactory = new CloningFactory();
-      for (int i = 0; i < 100000; i++) {
-        Console.Write("cloning storable.. ");
-        storableClones.Add(cloningFactory.Clone(storable));
-        Console.WriteLine();
-        Console.Write("cloning cloneable.. ");
-        clonableClones.Add((CloneableObject)cloneable.Clone());
-        Console.WriteLine();
-      }
-    }
-
-    public static void SpeedTest2() {
-      Root r = new Root();
-      r.selfReferences = new List<Root>();
-      r.selfReferences.Add(r);
-      r.selfReferences.Add(r);
-      r.c = new Custom();
-      r.c.r = r;
-      r.dict.Add("one", 1);
-      r.dict.Add("two", 2);
-      r.dict.Add("three", 3);
-
-      CloneableRoot cr = new CloneableRoot();
-      cr.selfReferences = new List<CloneableRoot>();
-      cr.selfReferences.Add(cr);
-      cr.selfReferences.Add(cr);
-      cr.c = new CloneableCustom();
-      cr.c.r = cr;
-      cr.dict.Add("one", 1);
-      cr.dict.Add("two", 2);
-      cr.dict.Add("three", 3);      
-      List<Root> storableClones = new List<Root>();
-      List<CloneableRoot> clonableClones = new List<CloneableRoot>();      
-      CloningFactory cloningFactory = new CloningFactory();
-
-      DateTime start = DateTime.Now;
-      Console.Write("cloning storable.. ");
-      for (int i = 0; i < 100000; i++) {       
-        storableClones.Add(cloningFactory.Clone(r));                        
-      }
-      Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
-
-      start = DateTime.Now;
-      Console.Write("cloning storable again.. ");
-      for (int i = 0; i < 100000; i++) {
-        storableClones.Add(cloningFactory.Clone(r));
-      }
-      Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
-
-
-      start = DateTime.Now;
-      Console.Write("cloning cloneable.. ");
-      for (int i = 0; i < 100000; i++) {        
-        clonableClones.Add((CloneableRoot)cr.Clone(new Dictionary<object, object>()));
-      }
-      Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
-      clonableClones.Clear();
-      
-    }
-
-    public static void Main() {
-      //Test1();
-      //Test2();
-      //SpeedTest();
-      SpeedTest2();
-      Console.In.ReadLine();
-    }
-  }
-}
Index: /branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj	(revision 1322)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj	(revision 1323)
@@ -57,5 +57,5 @@
     <Compile Include="StorableAttributeTests.cs" />
     <Compile Include="StorableAttribute.cs" />
-    <Compile Include="NewSerializationTest.cs" />
+    <Compile Include="Test\NewSerializationTest.cs" />
     <Compile Include="SerializationTest.cs" />
     <Compile Include="XmlFormatter.cs" />
Index: /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1322)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1323)
@@ -2,5 +2,4 @@
 using System.Collections;
 using System;
-using System.Reflection;
 
 namespace Persistence {
@@ -8,9 +7,9 @@
   public class Serializer : IEnumerable<ISerializationToken> {
 
-    private object obj;
-    private string rootName;
-    private Dictionary<object, int> obj2id;
-    private Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
-    private List<ICompoundSerializer> compoundSerializers;
+    private readonly object obj;
+    private readonly string rootName;
+    private readonly Dictionary<object, int> obj2id;
+    private readonly Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
+    private readonly List<ICompoundSerializer> compoundSerializers;
 
     public Serializer(object obj) :
@@ -34,15 +33,14 @@
       }
       this.compoundSerializers = new List<ICompoundSerializer>(compoundSerializers);
-      this.obj2id = new Dictionary<object, int>();
-      obj2id.Add(new object(), 0);
-    }
+      obj2id = new Dictionary<object, int> {{new object(), 0}};
+        }
 
     IEnumerator IEnumerable.GetEnumerator() {
-      return this.GetEnumerator();
+      return GetEnumerator();
     }
 
     public IEnumerator<ISerializationToken> GetEnumerator() {
       DataMemberAccessor rootAccessor = new DataMemberAccessor(
-        this.rootName, obj.GetType(), null, () => this.obj, null);
+        rootName, obj.GetType(), null, () => obj, null);
       IEnumerator<ISerializationToken> iterator = Serialize(rootAccessor);
       while (iterator.MoveNext())
@@ -54,16 +52,16 @@
       if (value == null) {
         yield return new NullReferenceToken(accessor.Name);
-      } else if (this.primitiveSerializers.ContainsKey(value.GetType())) {
-        yield return new PrimitiveToken(accessor, this.primitiveSerializers[value.GetType()].Serialize(value));
-      } else if (this.obj2id.ContainsKey(value)) {
-        yield return new ReferenceToken(accessor.Name, this.obj2id[value]);
+      } else if (primitiveSerializers.ContainsKey(value.GetType())) {
+        yield return new PrimitiveToken(accessor, primitiveSerializers[value.GetType()].Serialize(value));
+      } else if (obj2id.ContainsKey(value)) {
+        yield return new ReferenceToken(accessor.Name, obj2id[value]);
       } else {
         int id = obj2id.Count;
-        this.obj2id.Add(value, id);
+        obj2id.Add(value, id);
         yield return new BeginToken(accessor, id);
-        ICompoundSerializer customSerializer = this.FindCompoundSerializer(value.GetType());
+        ICompoundSerializer customSerializer = FindCompoundSerializer(value.GetType());
         if (customSerializer != null) {
-          foreach (object obj in customSerializer.Serialize(value)) {
-            IEnumerator<ISerializationToken> iterator = this.Serialize(new DataMemberAccessor(obj));
+          foreach (object o in customSerializer.Serialize(value)) {
+            IEnumerator<ISerializationToken> iterator = Serialize(new DataMemberAccessor(o));
             while (iterator.MoveNext())
               yield return iterator.Current;
@@ -74,5 +72,5 @@
             StorableAttribute.GetAutostorableAccessors(value)) {
             nSubComponents += 1;
-            IEnumerator<ISerializationToken> iterator = this.Serialize(mapping.Value);                        
+            IEnumerator<ISerializationToken> iterator = Serialize(mapping.Value);                        
             while (iterator.MoveNext()) {                            
               yield return iterator.Current;
Index: /branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs	(revision 1322)
+++ /branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs	(revision 1323)
@@ -1,7 +1,5 @@
 ﻿using System;
 using System.Collections.Generic;
-using System.Text;
 using System.Reflection;
-using System.Collections;
 
 namespace Persistence {
@@ -13,16 +11,6 @@
   public class StorableAttribute : Attribute {
 
-    private string name = null;
-    private object defaultValue = null;
-
-    public string Name {
-      get { return this.name; }
-      set { this.name = value; }
-    }
-
-    public object DefaultValue {
-      get { return this.defaultValue; }
-      set { this.defaultValue = value; }
-    }  
+    public string Name { get; set; }
+    public object DefaultValue { get; set; }
 
     private const BindingFlags instanceMembers =
@@ -31,18 +19,25 @@
       BindingFlags.NonPublic;
 
-    public static Dictionary<string, DataMemberAccessor> GetAutostorableAccessors(object obj) {
-      Dictionary<string, DataMemberAccessor> autoStorableAccessors = 
-        new Dictionary<string, DataMemberAccessor>();
+
+    public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> GetStorableMembers(object obj) {
       foreach (MemberInfo memberInfo in obj.GetType().GetMembers(instanceMembers)) {
         foreach (object attribute in memberInfo.GetCustomAttributes(false)) {          
-          StorableAttribute autoStorableAttribute =
+          StorableAttribute storableAttribute =
             attribute as StorableAttribute;
-          if (autoStorableAttribute != null) {
-            autoStorableAccessors.Add(memberInfo.Name,
-              new DataMemberAccessor(memberInfo, autoStorableAttribute, obj));
+          if (storableAttribute != null) {
+            yield return new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo);            
           }
         }
-      }
-      return autoStorableAccessors;
+      }      
+    }
+
+    public static Dictionary<string, DataMemberAccessor> GetAutostorableAccessors(object obj) {
+      Dictionary<string, DataMemberAccessor> storableAccessors =
+        new Dictionary<string, DataMemberAccessor>();
+      foreach (KeyValuePair<StorableAttribute, MemberInfo> pair in GetStorableMembers(obj)) {
+        storableAccessors.Add(pair.Value.Name,
+          new DataMemberAccessor(pair.Value, pair.Key, obj));
+      }            
+      return storableAccessors;
     }    
   }
@@ -50,5 +45,5 @@
   class CloningFactory {
 
-    private static CloningFactory instance = new CloningFactory();
+    private static readonly CloningFactory instance = new CloningFactory();
 
     public static T DefaultClone<T>(T obj) {
@@ -56,5 +51,5 @@
     }
 
-    private List<ICompoundSerializer> compoundSerializers;
+    private readonly List<ICompoundSerializer> compoundSerializers;
 
     public CloningFactory(IEnumerable<ICompoundSerializer> compoundSerializers) {
@@ -67,5 +62,5 @@
     delegate object CloneMethod(object obj, Dictionary<object, object> twins);
 
-    Dictionary<Type, CloneMethod> cloneMethods = new Dictionary<Type, CloneMethod>();
+    readonly Dictionary<Type, CloneMethod> cloneMethods = new Dictionary<Type, CloneMethod>();
 
     public T Clone<T>(T obj) {
@@ -75,10 +70,12 @@
 
     public T Clone<T>(T obj, Dictionary<object, object> twins) {
-      if (obj == null)
-        return default(T);
-
       ValueType t = obj as ValueType;
       if (t != null)
-        return (T)obj;
+        return obj;
+
+      // ReSharper disable CompareNonConstrainedGenericWithNull
+      if (obj == null)
+      // ReSharper restore CompareNonConstrainedGenericWithNull
+        return default(T);
 
       if (twins.ContainsKey(obj))
@@ -99,5 +96,5 @@
 
     private CloneMethod CreateCloneMethod(Type type) {
-      if (type.GetConstructor(new Type[] { type }) != null)
+      if (type.GetConstructor(new[] { type }) != null)
         return CopyConstructorCloneMethod.Create(type);
       foreach (ICompoundSerializer serializer in compoundSerializers)
@@ -111,11 +108,10 @@
         return new CopyConstructorCloneMethod(type).method;
       }
-      private ConstructorInfo constructorInfo;
+      private readonly ConstructorInfo constructorInfo;
       public CopyConstructorCloneMethod(Type type) {
-        this.constructorInfo = type.GetConstructor(new Type[] { type });
-      }
-
+        constructorInfo = type.GetConstructor(new[] { type });
+      }
       object method(object obj, Dictionary<object, object> twins) {
-        object newInstance = constructorInfo.Invoke(new object[] { obj });
+        object newInstance = constructorInfo.Invoke(new[] { obj });
         twins.Add(obj, newInstance);
         return newInstance;
@@ -128,7 +124,7 @@
         return new CompoundSerializerCloneMethod(serializer, type, factory).method;
       }
-      private ICompoundSerializer serializer;
-      private Type type;
-      private CloningFactory factory;
+      private readonly ICompoundSerializer serializer;
+      private readonly Type type;
+      private readonly CloningFactory factory;
       public CompoundSerializerCloneMethod(ICompoundSerializer serializer,
           Type type, CloningFactory factory) {
@@ -138,8 +134,8 @@
       }
       object method(object obj, Dictionary<object, object> twins) {
-        return serializer.DeSerialize(
+        return serializer.DeSerialize(          
           Functional.Map(
             serializer.Serialize(obj),
-            (o) => factory.Clone(o, twins)),
+            o => factory.Clone(o, twins)),
           type);
       }
@@ -148,13 +144,13 @@
     class StorableAccessorCloneMethod {
 
-      delegate object Getter(object target);
-      delegate void Setter(object target, object value);
+      delegate object GetterMethod(object target);
+      delegate void SetterMethod(object target, object value);
 
       struct FieldAccessor {      
-        public Getter Getter;
-        public Setter Setter;
-        public FieldAccessor(Getter getter, Setter setter) {
-          this.Getter = getter;
-          this.Setter = setter;
+        public readonly GetterMethod Getter;
+        public readonly SetterMethod Setter;
+        public FieldAccessor(GetterMethod getter, SetterMethod setter) {
+          Getter = getter;
+          Setter = setter;
         }
       }
@@ -169,10 +165,10 @@
       }
 
-      private List<FieldAccessor> fieldAccessors;
-      private CloningFactory factory;
+      private readonly List<FieldAccessor> fieldAccessors;
+      private readonly CloningFactory factory;
          
       public StorableAccessorCloneMethod(Type type, CloningFactory factory) {
         this.factory = factory;
-        this.fieldAccessors = new List<FieldAccessor>();
+        fieldAccessors = new List<FieldAccessor>();
         foreach (MemberInfo memberInfo in type.GetMembers(INSTANCE_MEMBERS)) {
           foreach (object attribute in memberInfo.GetCustomAttributes(false)) {
@@ -188,5 +184,5 @@
                 PropertyInfo pi = (PropertyInfo)memberInfo;
                 fieldAccessors.Add(new FieldAccessor(
-                  (target) => pi.GetValue(target, null),
+                  target => pi.GetValue(target, null),
                   (target, value) => pi.SetValue(target, value, null)));
               }
@@ -198,5 +194,5 @@
         object newInstance = Activator.CreateInstance(obj.GetType());
         twins.Add(obj, newInstance);
-        foreach (FieldAccessor fa in this.fieldAccessors) {
+        foreach (FieldAccessor fa in fieldAccessors) {
           fa.Setter(newInstance, factory.Clone(fa.Getter(obj), twins));
         }
@@ -219,9 +215,6 @@
     public delegate void Setter(object value);
 
-    private string name;
-    private Type type;
-    private object defaultValue;
-    private Getter getter;
-    private Setter setter;
+    private readonly Getter getter;
+    private readonly Setter setter;
 
     public DataMemberAccessor(
@@ -231,7 +224,7 @@
       if (memberInfo.MemberType == MemberTypes.Field) {
         FieldInfo fieldInfo = (FieldInfo)memberInfo;
-        this.getter = () => fieldInfo.GetValue(obj);
-        this.setter = (value) => fieldInfo.SetValue(obj, value);
-        this.type = fieldInfo.FieldType;
+        getter = () => fieldInfo.GetValue(obj);
+        setter = value => fieldInfo.SetValue(obj, value);
+        Type = fieldInfo.FieldType;
       } else if (memberInfo.MemberType == MemberTypes.Property) {
         PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
@@ -240,13 +233,13 @@
             "Storable properties must implement both a Get and a Set accessor. ");
         }
-        this.getter = () => propertyInfo.GetValue(obj, null);
-        this.setter = (value) => propertyInfo.SetValue(obj, value, null);
-        this.type = propertyInfo.PropertyType;
+        getter = () => propertyInfo.GetValue(obj, null);
+        setter = value => propertyInfo.SetValue(obj, value, null);
+        Type = propertyInfo.PropertyType;
       } else {
         throw new NotSupportedException(
                 "The Storable attribute can only be applied to fields and properties.");
       }      
-      this.name = autoStorableAttribute.Name != null ? autoStorableAttribute.Name : memberInfo.Name;      
-      this.defaultValue = autoStorableAttribute.DefaultValue;                  
+      Name = autoStorableAttribute.Name ?? memberInfo.Name;      
+      DefaultValue = autoStorableAttribute.DefaultValue;                  
     }
 
@@ -254,7 +247,7 @@
         string name, Type type, object defaultValue,
         Getter getter, Setter setter) {
-      this.name = name;
-      this.type = type;
-      this.defaultValue = defaultValue;
+      Name = name;
+      Type = type;
+      DefaultValue = defaultValue;
       this.getter = getter;
       this.setter = setter;
@@ -262,38 +255,27 @@
 
     public DataMemberAccessor(object o) {
-      this.name = "";
-      this.type = o.GetType();
-      this.defaultValue = null;
-      this.getter = () => o;
-      this.setter = null;
-    }
-
-    public string Name {
-      get { return this.name; }
-    }
-
-    public Type Type {
-      get { return this.type; }
-    }
-
-    public object DefaultValue {
-      get { return this.defaultValue; }
-    }
-
+      Name = "";
+      Type = o.GetType();
+      DefaultValue = null;
+      getter = () => o;
+      setter = null;
+    }
+
+    public string Name { get; private set; }
+    public Type Type { get; private set; }
+    public object DefaultValue { get; private set; }
     public object Get() {
-      return this.getter();
-    }
-
+      return getter();
+    }
     public void Set(object value) {
-      this.setter(value);
-    }
-
+      setter(value);
+    }
     public override string ToString() {
       return String.Format("DataMember({0}, {1}, {2}, {3}, {4}",
-        this.name,
-        this.type == null ? "<null>" : this.type.FullName,
-        this.defaultValue == null ? "<null>" : this.defaultValue,
-        this.getter.Method,
-        this.setter.Method);
+        Name,
+        Type == null ? "<null>" : Type.FullName,
+        DefaultValue ?? "<null>",
+        getter.Method,
+        setter.Method);
     }
   }
Index: /branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs	(revision 1323)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs	(revision 1323)
@@ -0,0 +1,250 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Collections;
+using System.IO;
+
+namespace Persistence.Test {
+
+  public class Root {
+    [Storable]
+    public int[] i = new[] { 3, 4, 5, 6 };
+    [Storable]
+    public string s;
+    [Storable]
+    public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
+    [Storable]
+    public List<int> intList = new List<int>(new[] { 321, 312, 321 });
+    [Storable]
+    public Custom c;
+    [Storable]
+    public List<Root> selfReferences;
+    [Storable]
+    public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
+    [Storable]
+    public bool boolean = true;
+    [Storable]
+    public DateTime dateTime;
+    [Storable]
+    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
+    [Storable]
+    public Dictionary<string, int> dict = new Dictionary<string, int>();
+  }
+
+  public class Custom {
+    [Storable]
+    public int i;
+    [Storable]
+    public Root r;
+    [Storable]
+    public string name = "Serial";
+  }
+
+  public class CloneableRoot {
+    public int[] i = new[] { 3, 4, 5, 6 };
+    public string s;
+    public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
+    public List<int> intList = new List<int>(new[] { 321, 312, 321 });
+    public CloneableCustom c;
+    public List<CloneableRoot> selfReferences;
+    public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
+    public bool boolean = true;
+    public DateTime dateTime;
+    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
+    public Dictionary<string, int> dict = new Dictionary<string, int>();    
+    public object Clone(Dictionary<object, object> twins) {
+      if (twins.ContainsKey(this))
+        return twins[this];      
+      CloneableRoot cr = new CloneableRoot();
+      twins.Add(this, cr);
+      cr.i = i;
+      cr.s = s;
+      cr.intArray = new ArrayList(intArray);
+      cr.intList = new List<int>(intList);
+      cr.c = (CloneableCustom)c.Clone(twins);
+      cr.selfReferences = new List<CloneableRoot>();
+      for (int j = 0; j < selfReferences.Count; j++) {
+        cr.selfReferences.Add(this);
+      }
+      cr.multiDimArray = (double[,])multiDimArray.Clone();
+      cr.dateTime = new DateTime(dateTime.Ticks);
+      cr.kvp = new KeyValuePair<string, int>(kvp.Key, kvp.Value);
+      cr.dict = new Dictionary<string, int>(dict);
+      return cr;
+    }    
+  }
+
+  public class CloneableCustom {    
+    public int i;    
+    public CloneableRoot r;    
+    public string name = "Serial";
+    public object Clone(Dictionary<object, object> twins) {
+      if (twins.ContainsKey(this))
+        return twins[this];
+      CloneableCustom cc = new CloneableCustom();
+      twins.Add(this, cc);
+      cc.i = i;
+      cc.r = (CloneableRoot)r.Clone(twins);
+      cc.name = name;
+      return cc;
+    }
+  }
+
+  public class Manager {
+
+    private DateTime lastLoadTime;
+    [Storable]
+    private DateTime lastLoadTimePersistence {
+      get { return lastLoadTime; }
+      // ReSharper disable ValueParameterNotUsed
+      set { lastLoadTime = DateTime.Now; }
+      // ReSharper restore ValueParameterNotUsed
+    }
+    [Storable]
+    private double? dbl;
+  }
+
+  public class StorableObject {
+
+    [Storable]
+    Dictionary<int, string> dict;
+
+    public void Init() {
+      dict = new Dictionary<int, string>();
+      for (int i = 0; i < 1000000; i++) {
+        dict.Add(i, i.ToString());
+      }
+    }
+  }
+
+  public class CloneableObject : ICloneable {
+
+    Dictionary<int, string> dict;
+
+    public void Init() {
+      dict = new Dictionary<int, string>();
+      for (int i = 0; i < 1000000; i++) {
+        dict.Add(i, i.ToString());
+      }
+    }
+    public object Clone() {
+      CloneableObject clone = new CloneableObject{
+                                  dict = new Dictionary<int, string>(dict)
+                                };
+      return clone;
+    }
+  }  
+
+  public class NewSerializationTest {
+
+    public static void Test1() {
+      Root r = new Root();
+      r.selfReferences = new List<Root> {r, r};
+      r.c = new Custom {r = r};
+      r.dict.Add("one", 1);
+      r.dict.Add("two", 2);
+      r.dict.Add("three", 3);
+      Serializer s = new Serializer(r);        
+      Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
+      StreamWriter writer = new StreamWriter("test.xml");
+      foreach (ISerializationToken token in s) {
+        string line = xmlFormatter.Format(token);
+        writer.Write(line);
+        Console.Out.Write(line);
+      }
+      writer.Close();
+      XmlParser parser = new XmlParser(new StreamReader("test.xml"));
+      DeSerializer deSerializer = new DeSerializer();        
+      object o = deSerializer.DeSerialize(parser);
+      Root t = CloningFactory.DefaultClone(r);
+      Console.Out.WriteLine(Util.AutoFormat(o, true));      
+    }
+
+    public static void Test2() {
+      Manager m = new Manager();      
+      Serializer s = new Serializer(m);
+      Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
+      StreamWriter writer = new StreamWriter("test2.xml");
+      foreach (ISerializationToken token in s) {
+        string line = xmlFormatter.Format(token);
+        writer.Write(line);
+        Console.Out.Write(line);
+      }
+      writer.Close();
+      XmlParser parser = new XmlParser(new StreamReader("test2.xml"));
+      DeSerializer deSerializer = new DeSerializer();
+      object o = deSerializer.DeSerialize(parser);
+      Manager n = CloningFactory.DefaultClone(m);
+      Console.Out.WriteLine(Util.AutoFormat(o, true));      
+    }
+
+    public static void SpeedTest() {
+      StorableObject storable = new StorableObject();
+      CloneableObject cloneable = new CloneableObject();
+      Console.Write("initializing...");
+      storable.Init();
+      cloneable.Init();
+      Console.WriteLine("done");
+      List<StorableObject> storableClones = new List<StorableObject>();
+      List<CloneableObject> clonableClones = new List<CloneableObject>();
+      CloningFactory cloningFactory = new CloningFactory();
+      for (int i = 0; i < 100000; i++) {
+        Console.Write("cloning storable.. ");
+        storableClones.Add(cloningFactory.Clone(storable));
+        Console.WriteLine();
+        Console.Write("cloning cloneable.. ");
+        clonableClones.Add((CloneableObject)cloneable.Clone());
+        Console.WriteLine();
+      }
+    }
+
+    public static void SpeedTest2() {
+      Root r = new Root();
+      r.selfReferences = new List<Root> {r, r};
+      r.c = new Custom {r = r};
+      r.dict.Add("one", 1);
+      r.dict.Add("two", 2);
+      r.dict.Add("three", 3);
+
+      CloneableRoot cr = new CloneableRoot();
+      cr.selfReferences = new List<CloneableRoot> {cr, cr};
+      cr.c = new CloneableCustom {r = cr};
+      cr.dict.Add("one", 1);
+      cr.dict.Add("two", 2);
+      cr.dict.Add("three", 3);      
+      List<Root> storableClones = new List<Root>();
+      List<CloneableRoot> clonableClones = new List<CloneableRoot>();      
+      CloningFactory cloningFactory = new CloningFactory();
+
+      DateTime start = DateTime.Now;
+      Console.Write("cloning storable.. ");
+      for (int i = 0; i < 100000; i++) {       
+        storableClones.Add(cloningFactory.Clone(r));                        
+      }
+      Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
+
+      start = DateTime.Now;
+      Console.Write("cloning storable again.. ");
+      for (int i = 0; i < 100000; i++) {
+        storableClones.Add(cloningFactory.Clone(r));
+      }
+      Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
+
+      start = DateTime.Now;
+      Console.Write("cloning cloneable.. ");
+      for (int i = 0; i < 100000; i++) {        
+        clonableClones.Add((CloneableRoot)cr.Clone(new Dictionary<object, object>()));
+      }
+      Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
+      clonableClones.Clear();
+      
+    }
+
+    public static void Main() {
+      //Test1();
+      //Test2();
+      //SpeedTest();
+      SpeedTest2();
+      Console.In.ReadLine();
+    }
+  }
+}
Index: /branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1322)
+++ /branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1323)
@@ -6,15 +6,16 @@
     delegate string Formatter(ISerializationToken token);
 
-    private Dictionary<Type, Formatter> formatters;
+    private readonly Dictionary<Type, Formatter> formatters;
     private int depth;
 
     public XmlFormatter() {
-      this.formatters = new Dictionary<Type, Formatter>();
-      this.formatters.Add(typeof(BeginToken), new Formatter(FormatBegin));
-      this.formatters.Add(typeof(EndToken), new Formatter(FormatEnd));
-      this.formatters.Add(typeof(PrimitiveToken), new Formatter(FormatData));
-      this.formatters.Add(typeof(ReferenceToken), new Formatter(FormatReference));
-      this.formatters.Add(typeof(NullReferenceToken), new Formatter(FormatNullReference));
-      this.depth = 0;
+      formatters = new Dictionary<Type, Formatter>{
+                       {typeof (BeginToken), FormatBegin},
+                       {typeof (EndToken), FormatEnd},
+                       {typeof (PrimitiveToken), FormatData},
+                       {typeof (ReferenceToken), FormatReference},
+                       {typeof (NullReferenceToken), FormatNullReference}
+                     };
+      depth = 0;
     }
 
@@ -24,5 +25,5 @@
 
     private string Prefix {
-      get { return new string(' ', this.depth * 2); }
+      get { return new string(' ', depth * 2); }
     }
 
@@ -31,12 +32,11 @@
       string result =
         String.Format("{0}<COMPOSITE name=\"{1}\" type=\"{2}\" id=\"{3}\">\n",
-          this.Prefix, beginToken.Accessor.Name, beginToken.Accessor.Get().GetType(), beginToken.Id);
-      this.depth += 1;
+          Prefix, beginToken.Accessor.Name, beginToken.Accessor.Get().GetType(), beginToken.Id);
+      depth += 1;
       return result;
     }
 
     private string FormatEnd(ISerializationToken token) {
-      EndToken endToken = (EndToken)token;
-      this.depth -= 1;
+      depth -= 1;
       return Prefix + "</COMPOSITE>\n";
     }
@@ -45,5 +45,5 @@
       PrimitiveToken dataToken = (PrimitiveToken)token;
       return String.Format("{0}<PRIMITIVE name=\"{1}\" type=\"{2}\">{3}</PRIMITIVE>\n",
-        this.Prefix, dataToken.accessor.Name, dataToken.accessor.Get().GetType(), dataToken.Data);
+        Prefix, dataToken.accessor.Name, dataToken.accessor.Get().GetType(), dataToken.Data);
     }
 
@@ -51,5 +51,5 @@
       ReferenceToken refToken = (ReferenceToken)token;
       return String.Format("{0}<REFERENCE name=\"{1}\" ref=\"{2}\"/>\n",
-        this.Prefix, refToken.Name, refToken.Id);
+        Prefix, refToken.Name, refToken.Id);
     }
 
@@ -57,5 +57,5 @@
       NullReferenceToken nullRefToken = (NullReferenceToken)token;
       return String.Format("{0}<NULL name=\"{1}\"/>\n",
-        this.Prefix, nullRefToken.Name);
+        Prefix, nullRefToken.Name);
     }
   }
