Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1348


Ignore:
Timestamp:
03/16/09 16:35:31 (16 years ago)
Author:
epitzer
Message:

Rename primitive serializers to formatters and compound/composite serializers to decomposers. (#506)

Location:
branches/New Persistence Exploration/Persistence
Files:
2 added
2 deleted
6 edited

Legend:

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

    r1339 r1348  
    11using System.Collections.Generic;
    22using System;
    3 namespace Persistence { 
     3using System.Reflection;
     4using System.Text;
     5
     6namespace Persistence {
    47
    58  public class DeSerializer {
     
    6265    private readonly Stack<IAccessibleObject> compositeStack;
    6366
    64     private readonly Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
    65     private readonly List<ICompoundSerializer> customSerializers;
     67    private readonly Dictionary<Type, IFormatter> primitiveSerializers;
     68    private readonly List<IDecomposer> customSerializers;
    6669
    6770    delegate void Thunk();
     
    6972
    7073    public DeSerializer() : this(
    71       InterfaceInstantiatior.InstantiateAll<IPrimitiveSerializer>(),
    72       InterfaceInstantiatior.InstantiateAll<ICompoundSerializer>()) {}   
     74      InterfaceInstantiatior.InstantiateAll<IFormatter>(),
     75      InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {}   
    7376
    7477    public DeSerializer(
    75         IEnumerable<IPrimitiveSerializer> primitiveSerializers,
    76         IEnumerable<ICompoundSerializer> customSerializers) {
     78        IEnumerable<IFormatter> primitiveSerializers,
     79        IEnumerable<IDecomposer> customSerializers) {
    7780      id2obj = new Dictionary<int, object>();
    7881      compositeStack = new Stack<IAccessibleObject>();
     
    8487                     {typeof (Null), NullHandler}
    8588                   };
    86       this.primitiveSerializers = new Dictionary<Type, IPrimitiveSerializer>();
    87       foreach (IPrimitiveSerializer ps in primitiveSerializers) {
     89      this.primitiveSerializers = new Dictionary<Type, IFormatter>();
     90      foreach (IFormatter ps in primitiveSerializers) {
    8891        this.primitiveSerializers.Add(ps.Type, ps);
    8992      }
    90       this.customSerializers = new List<ICompoundSerializer>(customSerializers);
     93      this.customSerializers = new List<IDecomposer>(customSerializers);
    9194    }
    9295
     
    119122    private void CompositeEndHandler(IParseToken token) {
    120123      CompositeEnd end = (CompositeEnd)token;
    121       ICompoundSerializer compoundSerializer = FindCompoundSerializer(end.Type);
    122       if (compoundSerializer != null) {
     124      IDecomposer decomposer = FindCompoundSerializer(end.Type);
     125      if (decomposer != null) {
    123126        CustomObject customObject = (CustomObject)compositeStack.Pop();
    124127        object deserializedObject =
    125           compoundSerializer.DeSerialize(customObject.customValues, end.Type);
     128          decomposer.DeSerialize(customObject.customValues, end.Type);
    126129        if ( end.Id != null )
    127130          id2obj[(int)end.Id] = deserializedObject;       
     
    133136      }
    134137    }
    135     private ICompoundSerializer FindCompoundSerializer(Type type) {
    136       foreach (ICompoundSerializer serializer in customSerializers) {
     138    private IDecomposer FindCompoundSerializer(Type type) {
     139      foreach (IDecomposer serializer in customSerializers) {
    137140        if (serializer.CanSerialize(type))
    138141          return serializer;
  • branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj

    r1338 r1348  
    5656    <Compile Include="Properties\AssemblyInfo.cs" />
    5757    <Compile Include="Serializer.cs" />
    58     <Compile Include="CompoundSerializers.cs" />
    59     <Compile Include="PrimitiveSerializers.cs" />
     58    <Compile Include="Decomposers.cs" />
     59    <Compile Include="PrimitiveFormatters.cs" />
    6060    <Compile Include="Test\NewSerializationTest.cs" />
    6161    <Compile Include="Tokens.cs" />
  • branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs

    r1339 r1348  
    1010    private readonly string rootName;
    1111    private readonly Dictionary<object, int> obj2id;
    12     private readonly Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
    13     private readonly List<ICompoundSerializer> compoundSerializers;
     12    private readonly Dictionary<Type, IFormatter> primitiveSerializers;
     13    private readonly List<IDecomposer> compoundSerializers;
    1414    private readonly Dictionary<Type, int> typeCache;
    1515
    1616    public Serializer(object obj) :
    1717      this(obj,
    18       InterfaceInstantiatior.InstantiateAll<IPrimitiveSerializer>(),
    19       InterfaceInstantiatior.InstantiateAll<ICompoundSerializer>()) {}
     18      InterfaceInstantiatior.InstantiateAll<IFormatter>(),
     19      InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {}
    2020
    2121    public Serializer(object obj,
    22         IEnumerable<IPrimitiveSerializer> primitiveSerializers,
    23         IEnumerable<ICompoundSerializer> compoundSerializers) :
     22        IEnumerable<IFormatter> primitiveSerializers,
     23        IEnumerable<IDecomposer> compoundSerializers) :
    2424      this(obj, primitiveSerializers, compoundSerializers, "ROOT") { }
    2525
    2626    public Serializer(object obj,
    27         IEnumerable<IPrimitiveSerializer> primitiveSerializers,
    28         IEnumerable<ICompoundSerializer> compoundSerializers, string rootName) {
     27        IEnumerable<IFormatter> primitiveSerializers,
     28        IEnumerable<IDecomposer> compoundSerializers, string rootName) {
    2929      this.obj = obj;
    3030      this.rootName = rootName;
    31       this.primitiveSerializers = new Dictionary<Type, IPrimitiveSerializer>();
    32       foreach (IPrimitiveSerializer serializer in primitiveSerializers) {
     31      this.primitiveSerializers = new Dictionary<Type, IFormatter>();
     32      foreach (IFormatter serializer in primitiveSerializers) {
    3333        this.primitiveSerializers.Add(serializer.Type, serializer);
    3434      }
    35       this.compoundSerializers = new List<ICompoundSerializer>(compoundSerializers);
     35      this.compoundSerializers = new List<IDecomposer>(compoundSerializers);
    3636      obj2id = new Dictionary<object, int> {{new object(), 0}};
    3737      typeCache = new Dictionary<Type, int>();
     
    4848      while (iterator.MoveNext())
    4949        yield return iterator.Current;
    50       Console.WriteLine("TypeCache:f");
    51       foreach ( var pair in typeCache )
    52         Console.WriteLine(pair.Key);
     50      Console.WriteLine("TypeCache:");
     51      foreach (var pair in typeCache) {               
     52        Console.WriteLine("<TYPE id=\"{0}\" AssemblyQualifiedName=\"{1}\">",
     53          pair.Value,
     54          pair.Key.AssemblyQualifiedName);
     55      }
    5356    }
    5457
     
    8689     
    8790      yield return new BeginToken(accessor, id);
    88       ICompoundSerializer customSerializer = FindCompoundSerializer(value.GetType());
     91      IDecomposer custom = FindCompoundSerializer(value.GetType());
    8992
    90       if (customSerializer != null) {
    91         foreach (object o in customSerializer.Serialize(value)) {
     93      if (custom != null) {
     94        foreach (object o in custom.Serialize(value)) {
    9295          IEnumerator<ISerializationToken> iterator = Serialize(new DataMemberAccessor(o));
    9396          while (iterator.MoveNext())
     
    115118    }
    116119
    117     private ICompoundSerializer FindCompoundSerializer(Type type) {
    118       foreach (ICompoundSerializer s in compoundSerializers) {
     120    private IDecomposer FindCompoundSerializer(Type type) {
     121      foreach (IDecomposer s in compoundSerializers) {
    119122        if (s.CanSerialize(type))
    120123          return s;
  • branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs

    r1338 r1348  
    5959    }
    6060
    61     private readonly List<ICompoundSerializer> compoundSerializers;
    62 
    63     public CloningFactory(IEnumerable<ICompoundSerializer> compoundSerializers) {
    64       this.compoundSerializers = new List<ICompoundSerializer>(compoundSerializers);
     61    private readonly List<IDecomposer> compoundSerializers;
     62
     63    public CloningFactory(IEnumerable<IDecomposer> compoundSerializers) {
     64      this.compoundSerializers = new List<IDecomposer>(compoundSerializers);
    6565    }
    6666
    6767    public CloningFactory() :
    68       this(InterfaceInstantiatior.InstantiateAll<ICompoundSerializer>()) { }
     68      this(InterfaceInstantiatior.InstantiateAll<IDecomposer>()) { }
    6969
    7070    delegate object CloneMethod(object obj, Dictionary<object, object> twins);
     
    106106      if (type.GetConstructor(new[] { type }) != null)
    107107        return CopyConstructorCloneMethod.Create(type);
    108       foreach (ICompoundSerializer serializer in compoundSerializers)
     108      foreach (IDecomposer serializer in compoundSerializers)
    109109        if (serializer.CanSerialize(type))
    110110          return CompoundSerializerCloneMethod.Create(serializer, type, this);
     
    128128
    129129    class CompoundSerializerCloneMethod {
    130       public static CloneMethod Create(ICompoundSerializer serializer,
     130      public static CloneMethod Create(IDecomposer serializer,
    131131          Type type, CloningFactory factory) {
    132132        return new CompoundSerializerCloneMethod(serializer, type, factory).method;
    133133      }
    134       private readonly ICompoundSerializer serializer;
     134      private readonly IDecomposer serializer;
    135135      private readonly Type type;
    136136      private readonly CloningFactory factory;
    137       public CompoundSerializerCloneMethod(ICompoundSerializer serializer,
     137      public CompoundSerializerCloneMethod(IDecomposer serializer,
    138138          Type type, CloningFactory factory) {
    139139        this.serializer = serializer;
  • branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs

    r1338 r1348  
    120120    }
    121121
    122     public static void Main() {
    123       int[] i = {1, 2, 3};
    124       object o = i;
    125       Type type = o.GetType().BaseType.BaseType;
    126       foreach (MemberInfo mi in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic )) {
    127         if ( mi.MemberType == MemberTypes.Field || mi.MemberType == MemberTypes.Property )
    128           Console.WriteLine(mi.Name);
    129       }
     122    public static void Main() {     
    130123      Test1();
    131124      //Test2();
  • branches/New Persistence Exploration/Persistence/Test/Test.csproj

    r1338 r1348  
    4949    <Compile Include="NewSerializationTest.cs" />
    5050  </ItemGroup>
     51  <ItemGroup>
     52    <Reference Include="System" />
     53    <Reference Include="System.Core">
     54      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     55    </Reference>
     56  </ItemGroup>
    5157</Project>
Note: See TracChangeset for help on using the changeset viewer.