Changeset 1336


Ignore:
Timestamp:
03/12/09 16:40:17 (12 years ago)
Author:
epitzer
Message:

Initialize non-serialized values with specified default values. (#506)

Location:
branches/New Persistence Exploration/Persistence/Persistence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs

    r1332 r1336  
    4444      public void SetValue(string name, object value) {
    4545        accessorDict[name].Set(value);
     46        accessorDict.Remove(name);
    4647      }
    4748      public Setter GetSetter(string name) {
    4849        return value => accessorDict[name].Set(value);
     50      }
     51      public void PopulateDefaultValues() {
     52        foreach (var pair in accessorDict) {
     53          pair.Value.Set(pair.Value.DefaultValue);
     54        }       
    4955      }
    5056    }
     
    106112        instance = Activator.CreateInstance(start.Type, true);
    107113        Dictionary<string, DataMemberAccessor> accessorDict =
    108         StorableAttribute.GetAutostorableAccessors(instance);
     114          StorableAttribute.GetAutostorableAccessors(instance);
    109115        compositeStack.Push(new CompositeObject(instance, accessorDict));
    110116        id2obj.Add(start.Id, instance);
     
    113119    private void CompositeEndHandler(IParseToken token) {
    114120      CompositeEnd end = (CompositeEnd)token;
    115       ICompoundSerializer customSerializer = FindCompoundSerializer(end.Type);
    116       if (customSerializer != null) {
     121      ICompoundSerializer compoundSerializer = FindCompoundSerializer(end.Type);
     122      if (compoundSerializer != null) {
    117123        CustomObject customObject = (CustomObject)compositeStack.Pop();
    118124        object deserializedObject =
    119           customSerializer.DeSerialize(customObject.customValues, end.Type);
     125          compoundSerializer.DeSerialize(customObject.customValues, end.Type);
    120126        id2obj[end.Id] = deserializedObject;       
    121127        SetValue(end.Name, deserializedObject);         
    122128      } else {
    123129        CompositeObject compositeObject = (CompositeObject)compositeStack.Pop();
     130        compositeObject.PopulateDefaultValues();
    124131        SetValue(end.Name, compositeObject.Obj);
    125132      }
  • branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs

    r1331 r1336  
    3434    [Storable]
    3535    public Dictionary<string, int> dict = new Dictionary<string, int>();
     36    [Storable(DefaultValue = "default")]
     37    public string uninitialized;
    3638  }
    3739
     
    151153      Serializer s = new Serializer(r);       
    152154      Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
    153       StreamWriter writer = new StreamWriter("test.xml");
     155      //StreamWriter writer = new StreamWriter("test.xml");
    154156      foreach (ISerializationToken token in s) {
    155157        string line = xmlFormatter.Format(token);
    156         writer.Write(line);
     158        //writer.Write(line);
    157159        Console.Out.Write(line);
    158160      }
    159       writer.Close();
     161      //writer.Close();
    160162      XmlParser parser = new XmlParser(new StreamReader("test.xml"));
    161163      DeSerializer deSerializer = new DeSerializer();       
Note: See TracChangeset for help on using the changeset viewer.