Index: /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1330)
@@ -135,5 +135,7 @@
       Primitive primitive = (Primitive)token;
       object value = primitiveSerializers[primitive.Type].DeSerialize(primitive.SerializedValue);
-      this.SetValue(primitive.Name, value);
+      if ( ! value.GetType().IsValueType )
+        id2obj[(int)primitive.Id] = value;
+      SetValue(primitive.Name, value);
     }
     private void ReferenceHandler(IParseToken token) {
Index: /branches/New Persistence Exploration/Persistence/Persistence/PrimitiveSerializers.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/PrimitiveSerializers.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/PrimitiveSerializers.cs	(revision 1330)
@@ -1,3 +1,5 @@
 ﻿using System;
+using System.Collections;
+using System.Collections.Generic;
 using System.Text;
 using System.Globalization;
@@ -20,5 +22,5 @@
       StringBuilder sb = new StringBuilder();
       foreach (string s in ((string)o).Split(
-        new string[] { "<![CDATA[", "]]>" },
+        new[] { "<![CDATA[", "]]>" },
         StringSplitOptions.RemoveEmptyEntries)) {
         sb.Append(s);
@@ -27,4 +29,5 @@
     }
   }
+
   public class Int2XMLSerializer : IPrimitiveSerializer {
     public Type Type { get { return typeof(int); } }
@@ -36,4 +39,5 @@
     }
   }
+
   public class Double2XmlSerializer : IPrimitiveSerializer {    
     public Type Type { get { return typeof(double); } }        
@@ -45,4 +49,5 @@
     }
   }
+
   public class Boolean2XmlSerializer : IPrimitiveSerializer {    
     public Type Type { get { return typeof(bool); } }    
@@ -54,4 +59,5 @@
     }
   }
+
   public class DateTime2XmlSerializer : IPrimitiveSerializer {    
     public Type Type { get { return typeof(DateTime); } }      
@@ -63,3 +69,106 @@
     }
   }
+
+  public abstract class NumberArray2XmlSerializer : IPrimitiveSerializer {
+    public abstract Type Type { get; }    
+    protected virtual string Separator { get { return ";"; } }
+    protected abstract string formatValue(object o);
+    protected abstract object parseValue(string o);
+    public object Serialize(object obj) {      
+      Array a = (Array)obj;
+      StringBuilder sb = new StringBuilder();
+      sb.Append(a.Rank);      
+      for (int i = 0; i < a.Rank; i++) {
+        sb.Append(Separator);
+        sb.Append(a.GetLength(i));
+      }
+      foreach (object o in a) {
+        sb.Append(Separator);
+        sb.Append(formatValue(o));
+      }
+      return sb.ToString();
+    }
+    public object DeSerialize(object o) {
+      IEnumerator values =
+        ((string) o)
+        .Split(new[] {Separator},
+        StringSplitOptions.RemoveEmptyEntries).GetEnumerator();
+      values.MoveNext();
+      int rank = int.Parse((string)values.Current);
+      int[] lengths = new int[rank];
+      for ( int i = 0; i<rank; i++ ) {
+        values.MoveNext();
+        lengths[i] = int.Parse((string)values.Current);
+      }
+      Array a = Array.CreateInstance(this.Type.GetElementType(), lengths);
+      int[] positions = new int[rank];
+      while ( values.MoveNext() ) {
+        a.SetValue(parseValue((string)values.Current), positions);
+        positions[0] += 1;
+        for ( int i = 0; i<rank-1; i++) {
+          if (positions[i] >= lengths[i]) {
+            positions[i] = 0;
+            positions[i + 1] += 1;
+          } else {
+            break;
+          }
+        }
+      }
+      return a;
+    }
+  }
+  public class IntArray2XmlSerializer : NumberArray2XmlSerializer {
+    public override Type Type { get { return typeof(int[]); } }
+    protected override string formatValue(object o) { return o.ToString(); }
+    protected override object parseValue(string o) { return int.Parse(o); }
+  }
+  public class Int2DArray2XmlSerializer : IntArray2XmlSerializer {
+    public override Type Type { get { return typeof (int[,]); } }
+  }
+  public class Int3DArray2XmlSerializer : IntArray2XmlSerializer {
+    public override Type Type { get { return typeof(int[,,]); } }
+  }
+  public class DoubleArray2XmlSerializer : NumberArray2XmlSerializer {
+    public override Type Type { get { return typeof(double[]); } }
+    protected override string formatValue(object o) { return ((double) o).ToString("r"); }
+    protected override object parseValue(string o) { return double.Parse(o); }    
+  }
+  public class Double2DArray2XmlSerializer : DoubleArray2XmlSerializer {
+    public override Type Type { get { return typeof(double[,]); } }    
+  }
+  public class Double3DArray2XmlSerializer : DoubleArray2XmlSerializer {
+    public override Type Type { get { return typeof(double[,,]); } }
+  }
+
+  public abstract class NumberEnumeration2XmlSerializer : IPrimitiveSerializer {
+    public abstract Type Type { get; }
+    protected virtual string Separator { get { return ";"; } }
+    protected abstract void Add(IEnumerable enumeration, object o);
+    protected abstract object Instantiate();
+    protected abstract string formatValue(object o);
+    protected abstract object parseValue(string o);    
+    public object Serialize(object o) {
+      StringBuilder sb = new StringBuilder();
+      foreach (var value in (IEnumerable) o) {        
+        sb.Append(formatValue(value));
+        sb.Append(Separator);
+      }
+      return sb.ToString();
+    }  
+    public object DeSerialize(object o) {
+      IEnumerable enumeration = (IEnumerable) Instantiate();        
+      string[] values = ((string) o).Split(new[] {Separator}, StringSplitOptions.RemoveEmptyEntries);
+      foreach ( var value in values ) {
+        Add(enumeration, parseValue(value));
+      }
+      return enumeration;
+    }
+  }
+  public class IntList2XmlSerializer : NumberEnumeration2XmlSerializer {
+    public override Type Type { get { return typeof(List<int>); } }
+    protected override void Add(IEnumerable enumeration, object o) { ((List<int>)enumeration).Add((int)o); }
+    protected override object Instantiate() { return new List<int>(); }
+    protected override string formatValue(object o) { return o.ToString(); }
+    protected override object parseValue(string o) { return int.Parse(o); }
+  }  
 }
Index: /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1330)
@@ -52,8 +52,16 @@
       if (value == null) {
         yield return new NullReferenceToken(accessor.Name);
-      } 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 if (primitiveSerializers.ContainsKey(value.GetType())) {
+        int? id = null;
+        if ( ! value.GetType().IsValueType ) {
+          id = obj2id.Count;
+          obj2id.Add(value, (int)id);
+        }
+        yield return new PrimitiveToken(
+          accessor,
+          primitiveSerializers[value.GetType()].Serialize(value),
+          id);      
       } else {
         int id = obj2id.Count;
Index: /branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs	(revision 1330)
@@ -232,5 +232,5 @@
         if (!propertyInfo.CanRead || !propertyInfo.CanWrite) {
           throw new NotSupportedException(
-            "Storable properties must implement both a Get and a Set accessor. ");
+            "Storable properties must implement both a Get and a Set Accessor. ");
         }
         getter = () => propertyInfo.GetValue(obj, null);
@@ -255,6 +255,5 @@
     }
 
-    public DataMemberAccessor(object o) {
-      Name = "";
+    public DataMemberAccessor(object o) {      
       Type = o.GetType();
       DefaultValue = null;
Index: /branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs	(revision 1330)
@@ -7,39 +7,41 @@
   }
   public class BeginToken : ISerializationToken {
-    public DataMemberAccessor Accessor;
-    public int Id;
+    public readonly DataMemberAccessor Accessor;
+    public readonly int Id;
     public BeginToken(DataMemberAccessor accessor, int id) {
-      this.Accessor = accessor;
-      this.Id = id;
+      Accessor = accessor;
+      Id = id;
     }
   }
   public class EndToken : ISerializationToken {
-    public DataMemberAccessor Accessor;
-    public int Id;
+    public readonly DataMemberAccessor Accessor;
+    public readonly int Id;
     public EndToken(DataMemberAccessor accessor, int id) {
-      this.Accessor = accessor;
-      this.Id = id;
+      Accessor = accessor;
+      Id = id;
     }
   }
   public class PrimitiveToken : ISerializationToken {
-    public DataMemberAccessor accessor;
-    public object Data;
-    public PrimitiveToken(DataMemberAccessor accessor, object data) {
-      this.accessor = accessor;
-      this.Data = data;
+    public readonly DataMemberAccessor Accessor;
+    public readonly object Data;
+    public readonly int? Id;
+    public PrimitiveToken(DataMemberAccessor accessor, object data, int? id) {
+      Accessor = accessor;
+      Data = data;
+      Id = id;
     }
   }
   public class ReferenceToken : ISerializationToken {
-    public string Name;
-    public int Id;
+    public readonly string Name;
+    public readonly int Id;
     public ReferenceToken(string name, int id) {
-      this.Name = name;
-      this.Id = id;
+      Name = name;
+      Id = id;
     }
   }
   public class NullReferenceToken : ISerializationToken {
-    public string Name;
+    public readonly string Name;
     public NullReferenceToken(string name) {
-      this.Name = name;
+      Name = name;
     }
   }
@@ -51,45 +53,47 @@
 
   public class CompositeStart : IParseToken {
-    public string Name;
-    public Type Type;
-    public int Id;
+    public readonly string Name;
+    public readonly Type Type;
+    public readonly int Id;
     public CompositeStart(string name, Type type, int id) {
-      this.Name = name;
-      this.Type = type;
-      this.Id = id;
+      Name = name;
+      Type = type;
+      Id = id;
     }
   }
   public class CompositeEnd : IParseToken {
-    public string Name;
-    public Type Type;
-    public int Id;
+    public readonly string Name;
+    public readonly Type Type;
+    public readonly int Id;
     public CompositeEnd(string name, Type type, int id) {
-      this.Name = name;
-      this.Type = type;
-      this.Id = id;
+      Name = name;
+      Type = type;
+      Id = id;
     }
   }
   public class Primitive : IParseToken {
-    public string Name;
-    public Type Type;
-    public string SerializedValue;
-    public Primitive(string name, Type type, string serilaizedValue) {
-      this.Name = name;
-      this.Type = type;
-      this.SerializedValue = serilaizedValue;
+    public readonly string Name;
+    public readonly Type Type;
+    public readonly string SerializedValue;
+    public readonly int? Id;
+    public Primitive(string name, Type type, string serilaizedValue, int? id) {
+      Name = name;
+      Type = type;
+      SerializedValue = serilaizedValue;
+      Id = id;
     }
   }
   public class Reference : IParseToken {
-    public string Name;
-    public int Id;
+    public readonly string Name;
+    public readonly int Id;
     public Reference(string name, int id) {
-      this.Name = name;
-      this.Id = id;
+      Name = name;
+      Id = id;
     }
   }
   public class Null : IParseToken {
-    public string Name;
+    public readonly string Name;
     public Null(string name) {
-      this.Name = name;
+      Name = name;
     }
   }
Index: /branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1330)
@@ -1,4 +1,6 @@
 ﻿using System.Collections.Generic;
 using System;
+using System.Xml;
+using System.Text;
 namespace Persistence {
   public class XmlFormatter {
@@ -13,9 +15,30 @@
                        {typeof (BeginToken), FormatBegin},
                        {typeof (EndToken), FormatEnd},
-                       {typeof (PrimitiveToken), FormatData},
+                       {typeof (PrimitiveToken), FormatPrimitive},
                        {typeof (ReferenceToken), FormatReference},
                        {typeof (NullReferenceToken), FormatNullReference}
                      };
       depth = 0;
+    }
+
+    private enum NodeType { Start, End, Inline } ;
+
+    private static string FormatNode(string name, Dictionary<string, string> attributes, NodeType type) {
+      StringBuilder sb = new StringBuilder();
+      sb.Append('<');
+      if (type == NodeType.End)
+        sb.Append('/');
+      sb.Append(name);      
+      foreach (var attribute in attributes) {
+        sb.Append(' ');
+        sb.Append(attribute.Key);
+        sb.Append("=\"");
+        sb.Append(attribute.Value);
+        sb.Append('"');
+      }
+      if (type == NodeType.Inline)
+        sb.Append('/');
+      sb.Append(">");
+      return sb.ToString();      
     }
 
@@ -30,32 +53,50 @@
     private string FormatBegin(ISerializationToken token) {
       BeginToken beginToken = (BeginToken)token;
-      string result =
-        String.Format("{0}<COMPOSITE name=\"{1}\" type=\"{2}\" id=\"{3}\">\n",
-          Prefix, beginToken.Accessor.Name, beginToken.Accessor.Get().GetType(), beginToken.Id);
+      string result = Prefix +
+                      FormatNode("COMPOSITE",
+                                 new Dictionary<string, string>
+                                   {
+                                     {"name", beginToken.Accessor.Name},
+                                     {"type", beginToken.Accessor.Get().GetType().ToString()},
+                                     {"id", beginToken.Id.ToString()}
+                                   }, NodeType.Start) + "\n";
       depth += 1;
       return result;
     }
 
-    private string FormatEnd(ISerializationToken token) {
+    private string FormatEnd(ISerializationToken token) {      
       depth -= 1;
       return Prefix + "</COMPOSITE>\n";
     }
 
-    private string FormatData(ISerializationToken token) {
+    private string FormatPrimitive(ISerializationToken token) {
       PrimitiveToken dataToken = (PrimitiveToken)token;
-      return String.Format("{0}<PRIMITIVE name=\"{1}\" type=\"{2}\">{3}</PRIMITIVE>\n",
-        Prefix, dataToken.accessor.Name, dataToken.accessor.Get().GetType(), dataToken.Data);
+      Dictionary<string, string> attributes =
+        new Dictionary<string, string> {
+            {"type", dataToken.Accessor.Get().GetType().ToString()}};
+      if ( dataToken.Accessor.Name != "" )
+        attributes.Add("name", dataToken.Accessor.Name);
+      if ( dataToken.Id != null )
+        attributes.Add("id", dataToken.Id.ToString());
+      return Prefix +
+        FormatNode("PRIMITIVE", attributes, NodeType.Start) +
+        dataToken.Data + "</PRIMITIVE>\n";      
     }
 
     private string FormatReference(ISerializationToken token) {
-      ReferenceToken refToken = (ReferenceToken)token;
-      return String.Format("{0}<REFERENCE name=\"{1}\" ref=\"{2}\"/>\n",
-        Prefix, refToken.Name, refToken.Id);
+      ReferenceToken refToken = (ReferenceToken) token;
+      Dictionary<string, string> attributes =
+        new Dictionary<string, string> {{"ref", refToken.Id.ToString()}};
+      if ( refToken.Name != null )
+        attributes.Add("name", refToken.Name);
+      return Prefix + FormatNode("REFERENCE", attributes, NodeType.Inline) + "\n";  
     }
 
     private string FormatNullReference(ISerializationToken token) {
       NullReferenceToken nullRefToken = (NullReferenceToken)token;
-      return String.Format("{0}<NULL name=\"{1}\"/>\n",
-        Prefix, nullRefToken.Name);
+      Dictionary<string, string> attributes = new Dictionary<string, string>();
+      if (nullRefToken.Name != null)
+        attributes.Add("name", nullRefToken.Name);
+      return Prefix + FormatNode("NULL", attributes, NodeType.Inline) + "\n";
     }
   }
Index: /branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs	(revision 1329)
+++ /branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs	(revision 1330)
@@ -8,22 +8,24 @@
   public class XmlParser : IEnumerable<IParseToken> {
 
-    private XmlReader reader;
+    private readonly XmlReader reader;
     private delegate IEnumerator<IParseToken> Handler();
-    private Dictionary<string, Handler> handlers;
+    private readonly Dictionary<string, Handler> handlers;
 
-    public XmlParser(StreamReader input) {
-      XmlReaderSettings settings = new XmlReaderSettings();
-      settings.ConformanceLevel = ConformanceLevel.Document;
-      settings.IgnoreWhitespace = true;
-      settings.IgnoreComments = true;
-      this.reader = XmlReader.Create(input, settings);
-      this.handlers = new Dictionary<string, Handler>();
-      this.handlers.Add("PRIMITIVE", new Handler(ParsePrimitive));
-      this.handlers.Add("COMPOSITE", new Handler(ParseComposite));
-      this.handlers.Add("REFERENCE", new Handler(ParseReference));
-      this.handlers.Add("NULL", new Handler(ParseNull));
+    public XmlParser(TextReader input) {
+      XmlReaderSettings settings = new XmlReaderSettings {
+                                       ConformanceLevel = ConformanceLevel.Document,
+                                       IgnoreWhitespace = true,
+                                       IgnoreComments = true
+                                     };
+      reader = XmlReader.Create(input, settings);
+      handlers = new Dictionary<string, Handler> {
+                     {"PRIMITIVE", ParsePrimitive},
+                     {"COMPOSITE", ParseComposite},
+                     {"REFERENCE", ParseReference},
+                     {"NULL", ParseNull}
+                   };
     }
     public IEnumerator<IParseToken> GetEnumerator() {
-      while (this.reader.Read()) {
+      while (reader.Read()) {
         if (!reader.IsStartElement()) {
           break;
@@ -44,15 +46,20 @@
     }
     private IEnumerator<IParseToken> ParsePrimitive() {
+      int? id = null;
+      string idString = reader.GetAttribute("id");
+      if (idString != null)
+        id = int.Parse(idString);
       yield return new Primitive(
-        this.reader.GetAttribute("name"),
-        Type.GetType(this.reader.GetAttribute("type")),
-        this.reader.ReadString());
+        reader.GetAttribute("name"),
+        Type.GetType(reader.GetAttribute("type")),
+        reader.ReadString(),
+        id);
     }
     private IEnumerator<IParseToken> ParseComposite() {
-      string name = this.reader.GetAttribute("name");
-      Type type = Type.GetType(this.reader.GetAttribute("type"));
-      int id = int.Parse(this.reader.GetAttribute("id"));
+      string name = reader.GetAttribute("name");
+      Type type = Type.GetType(reader.GetAttribute("type"));
+      int id = int.Parse(reader.GetAttribute("id"));
       yield return new CompositeStart(name, type, id);
-      IEnumerator<IParseToken> iterator = this.GetEnumerator();
+      IEnumerator<IParseToken> iterator = GetEnumerator();
       while (iterator.MoveNext())
         yield return iterator.Current;
@@ -61,12 +68,12 @@
     private IEnumerator<IParseToken> ParseReference() {
       yield return new Reference(
-        this.reader.GetAttribute("name"),
-        int.Parse(this.reader.GetAttribute("ref")));
+        reader.GetAttribute("name"),
+        int.Parse(reader.GetAttribute("ref")));
     }
     private IEnumerator<IParseToken> ParseNull() {
-      yield return new Null(this.reader.GetAttribute("name"));
+      yield return new Null(reader.GetAttribute("name"));
     }
     IEnumerator IEnumerable.GetEnumerator() {
-      return this.GetEnumerator();
+      return GetEnumerator();
     }
   }  
