- Timestamp:
- 03/09/09 15:33:44 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence/Persistence
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
r1317 r1318 67 67 private List<Thunk> finalFixes; 68 68 69 public DeSerializer() : this( 70 InterfaceInstantiatior.InstantiateAll<IPrimitiveSerializer>(), 71 InterfaceInstantiatior.InstantiateAll<ICompoundSerializer>()) {} 72 69 73 public DeSerializer( 70 74 IEnumerable<IPrimitiveSerializer> primitiveSerializers, … … 83 87 } 84 88 this.customSerializers = new List<ICompoundSerializer>(customSerializers); 85 this.finalFixes = new List<Thunk>();86 89 } 87 90 88 91 public object DeSerialize(IEnumerable<IParseToken> tokens) { 92 this.finalFixes = new List<Thunk>(); 89 93 foreach (IParseToken token in tokens) { 90 94 handlers[token.GetType()].Invoke(token); … … 95 99 return compositeStack.Pop().Obj; 96 100 } 101 97 102 private void CompositeStartHandler(IParseToken token) { 98 103 CompositeStart start = (CompositeStart)token; -
branches/New Persistence Exploration/Persistence/Persistence/NewSerializationTest.cs
r1317 r1318 53 53 r.dict.Add("two", 2); 54 54 r.dict.Add("three", 3); 55 56 Serializer s = new Serializer(r, 57 new IPrimitiveSerializer[] { 58 new String2XMLSerializer(), 59 new Int2XMLSerializer(), 60 new Double2XmlSerializer(), 61 new Boolean2XmlSerializer(), 62 new DateTime2XmlSerializer(), 63 }, new ICompoundSerializer[] { 64 new EnumerableSerializer(), 65 new ArraySerializer(), 66 new KeyValuePair2XmlSerializer(), 67 new Dictionary2XmlSerializer(), 68 }); 55 Serializer s = new Serializer(r); 69 56 Persistence.XmlFormatter xmlFormatter = new Persistence.XmlFormatter(); 70 57 StreamWriter writer = new StreamWriter("test.xml"); … … 76 63 writer.Close(); 77 64 XmlParser parser = new XmlParser(new StreamReader("test.xml")); 78 DeSerializer deSerializer = new DeSerializer( 79 new IPrimitiveSerializer[] { 80 new Int2XMLSerializer(), 81 new String2XMLSerializer(), 82 new Double2XmlSerializer(), 83 new Boolean2XmlSerializer(), 84 new DateTime2XmlSerializer(), 85 }, 86 new ICompoundSerializer[] { 87 new ArraySerializer(), 88 new EnumerableSerializer(), 89 new KeyValuePair2XmlSerializer(), 90 new Dictionary2XmlSerializer(), 91 }); 65 DeSerializer deSerializer = new DeSerializer(); 92 66 object o = deSerializer.DeSerialize(parser); 93 67 Console.Out.WriteLine(Util.AutoFormat(o, true)); -
branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
r1317 r1318 2 2 using System.Collections; 3 3 using System; 4 using System.Reflection; 4 5 5 6 namespace Persistence { … … 12 13 private Dictionary<Type, IPrimitiveSerializer> primitiveSerializers; 13 14 private List<ICompoundSerializer> compoundSerializers; 15 16 public Serializer(object obj) : 17 this(obj, 18 InterfaceInstantiatior.InstantiateAll<IPrimitiveSerializer>(), 19 InterfaceInstantiatior.InstantiateAll<ICompoundSerializer>()) {} 14 20 15 21 public Serializer(object obj, -
branches/New Persistence Exploration/Persistence/Persistence/Util.cs
r1279 r1318 5 5 6 6 namespace Persistence { 7 public class InterfaceInstantiatior { 8 public static List<T> InstantiateAll<T>() { 9 return InstantiateAll<T>(Assembly.GetExecutingAssembly()); 10 } 11 public static List<T> InstantiateAll<T>(Assembly a) { 12 List<T> instances = new List<T>(); 13 foreach (Type t in a.GetTypes()) { 14 if (t.GetInterface(typeof(T).FullName) != null) { 15 ConstructorInfo ci = t.GetConstructor(new Type[] { }); 16 if (ci != null) { 17 instances.Add((T)ci.Invoke(new object[] { })); 18 } 19 } 20 } 21 return instances; 22 } 23 } 7 24 public class Util { 8 25 public static string AutoFormat(object o) {
Note: See TracChangeset
for help on using the changeset viewer.