Free cookie consent management tool by TermsFeed Policy Generator

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

refactoring/resharping

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

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence

    • Property svn:ignore
      •  

        old new  
        22.gitignore
        33*.suo
         4_ReSharper.Persistence
  • branches/New Persistence Exploration/Persistence/Persistence.sln

    r1321 r1329  
    33# Visual Studio 2008
    44Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence", "Persistence\Persistence.csproj", "{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}"
    5 EndProject
    6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistenceTest", "PersistenceTest\PersistenceTest.csproj", "{019D994A-9E37-4A4C-BBDD-914AB9A9634C}"
    75EndProject
    86Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F65B17D-22F7-4A48-8762-74BB8BE3E0E5}"
     
    2927    {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|Any CPU.Build.0 = Release|Any CPU
    3028    {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|x86.ActiveCfg = Release|Any CPU
    31     {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    32     {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|Any CPU.Build.0 = Debug|Any CPU
    33     {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|x86.ActiveCfg = Debug|Any CPU
    34     {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|Any CPU.ActiveCfg = Release|Any CPU
    35     {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|Any CPU.Build.0 = Release|Any CPU
    36     {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|x86.ActiveCfg = Release|Any CPU
    3729  EndGlobalSection
    3830  GlobalSection(SolutionProperties) = preSolution
  • branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs

    r1318 r1329  
    1515
    1616    class CustomObject : IAccessibleObject {
    17       public object Obj { get { return this.obj; } }
    18       private object obj;
    19       public List<object> customValues;
     17      public object Obj { get; private set; }
     18      public readonly List<object> customValues;
    2019      public CustomObject(object obj) {
    21         this.obj = obj;
    22         this.customValues = new List<object>();
     20        Obj = obj;
     21        customValues = new List<object>();
    2322      }
    2423      public void AddValue(object value) {
     
    2726      public Setter GetSetter(string name) {
    2827        int index = customValues.Count-1;
    29         return (value) => customValues[index] = value;
     28        return value => customValues[index] = value;
    3029      }
    3130    }
    3231
    3332    class CompositeObject : IAccessibleObject {
    34       public object Obj { get { return this.obj; } }
    35       public object obj;
    36       public Dictionary<string, DataMemberAccessor> accessorDict;
     33      public object Obj { get; private set; }
     34      public readonly Dictionary<string, DataMemberAccessor> accessorDict;
    3735      public CompositeObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) {
    38         this.obj = obj;
     36        Obj = obj;
    3937        this.accessorDict = new Dictionary<string, DataMemberAccessor>();
    4038        foreach (KeyValuePair<string, DataMemberAccessor> pair in accessorDict) {
     
    4745        accessorDict[name].Set(value);
    4846      }
    49       public void SetAllDefaultValues() {
    50         throw new NotImplementedException();
    51       }
    5247      public Setter GetSetter(string name) {
    53         return (value) => accessorDict[name].Set(value);
     48        return value => accessorDict[name].Set(value);
    5449      }
    5550    }
     
    5752    private delegate void Handler(IParseToken token);
    5853
    59     private Dictionary<int, object> id2obj;
    60     private Dictionary<Type, Handler> handlers;
    61     private Stack<IAccessibleObject> compositeStack;
     54    private readonly Dictionary<int, object> id2obj;
     55    private readonly Dictionary<Type, Handler> handlers;
     56    private readonly Stack<IAccessibleObject> compositeStack;
    6257
    63     private Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
    64     private List<ICompoundSerializer> customSerializers;
     58    private readonly Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
     59    private readonly List<ICompoundSerializer> customSerializers;
    6560
    6661    delegate void Thunk();
     
    7671      id2obj = new Dictionary<int, object>();
    7772      compositeStack = new Stack<IAccessibleObject>();
    78       handlers = new Dictionary<Type, Handler>();
    79       handlers.Add(typeof(CompositeStart), new Handler(CompositeStartHandler));
    80       handlers.Add(typeof(CompositeEnd), new Handler(CompositeEndHandler));
    81       handlers.Add(typeof(Primitive), new Handler(PrimitiveHandler));
    82       handlers.Add(typeof(Reference), new Handler(ReferenceHandler));
    83       handlers.Add(typeof(Null), new Handler(NullHandler));     
     73      handlers = new Dictionary<Type, Handler> {
     74                     {typeof (CompositeStart), CompositeStartHandler},
     75                     {typeof (CompositeEnd), CompositeEndHandler},
     76                     {typeof (Primitive), PrimitiveHandler},
     77                     {typeof (Reference), ReferenceHandler},
     78                     {typeof (Null), NullHandler}
     79                   };
    8480      this.primitiveSerializers = new Dictionary<Type, IPrimitiveSerializer>();
    8581      foreach (IPrimitiveSerializer ps in primitiveSerializers) {
     
    9086
    9187    public object DeSerialize(IEnumerable<IParseToken> tokens) {
    92       this.finalFixes = new List<Thunk>();
     88      finalFixes = new List<Thunk>();
    9389      foreach (IParseToken token in tokens) {
    9490        handlers[token.GetType()].Invoke(token);
    9591      }
    96       foreach (Thunk fix in this.finalFixes) {
     92      foreach (Thunk fix in finalFixes) {
    9793        fix();
    9894      }
     
    10298    private void CompositeStartHandler(IParseToken token) {
    10399      CompositeStart start = (CompositeStart)token;
    104       object instance = null;
    105       if (this.FindCompoundSerializer(start.Type) != null) {
     100      object instance;
     101      if (FindCompoundSerializer(start.Type) != null) {
    106102        instance = new ParentReference();
    107103        compositeStack.Push(new CustomObject(instance));
     
    117113    private void CompositeEndHandler(IParseToken token) {
    118114      CompositeEnd end = (CompositeEnd)token;
    119       ICompoundSerializer customSerializer = this.FindCompoundSerializer(end.Type);
     115      ICompoundSerializer customSerializer = FindCompoundSerializer(end.Type);
    120116      if (customSerializer != null) {
    121117        CustomObject customObject = (CustomObject)compositeStack.Pop();
    122118        object deserializedObject =
    123119          customSerializer.DeSerialize(customObject.customValues, end.Type);
    124         this.id2obj[end.Id] = deserializedObject;       
    125         this.SetValue(end.Name, deserializedObject);         
     120        id2obj[end.Id] = deserializedObject;       
     121        SetValue(end.Name, deserializedObject);         
    126122      } else {
    127123        CompositeObject compositeObject = (CompositeObject)compositeStack.Pop();
    128         this.SetValue(end.Name, compositeObject.obj);
     124        SetValue(end.Name, compositeObject.Obj);
    129125      }
    130126    }
     
    143139    private void ReferenceHandler(IParseToken token) {
    144140      Reference reference = (Reference)token;
    145       object referredObject = this.id2obj[reference.Id];
    146       this.SetValue(reference.Name, this.id2obj[reference.Id]);
     141      object referredObject = id2obj[reference.Id];
     142      SetValue(reference.Name, id2obj[reference.Id]);
    147143      if (referredObject is ParentReference) {
    148144        Setter set = compositeStack.Peek().GetSetter(reference.Name);       
    149145        int id = reference.Id;
    150         this.finalFixes.Add(() => set(id2obj[id]));
     146        finalFixes.Add(() => set(id2obj[id]));
    151147      }
    152148    }
    153149    private void NullHandler(IParseToken token) {
    154150      Null nil = (Null)token;
    155       this.SetValue(nil.Name, null);
     151      SetValue(nil.Name, null);
    156152    }
    157153    private void SetValue(string name, object value) {
  • branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj

    r1324 r1329  
    5858    <Compile Include="Tokens.cs" />
    5959    <Compile Include="Util.cs" />
    60     <Compile Include="StorableAttributeTests.cs" />
     60    <Compile Include="Test\StorableAttributeTests.cs" />
    6161    <Compile Include="StorableAttribute.cs" />
    6262    <Compile Include="Test\NewSerializationTest.cs" />
    63     <Compile Include="SerializationTest.cs" />
     63    <Compile Include="Test\SerializationTest.cs" />
    6464    <Compile Include="XmlFormatter.cs" />
    6565    <Compile Include="XmlParser.cs" />
  • branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs

    r1323 r1329  
    2626    public DateTime dateTime;
    2727    [Storable]
    28     public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
     28    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("Serial", 123);
    2929    [Storable]
    3030    public Dictionary<string, int> dict = new Dictionary<string, int>();
     
    241241
    242242    public static void Main() {
    243       //Test1();
     243      Test1();
    244244      //Test2();
    245245      //SpeedTest();
    246       SpeedTest2();
     246      //SpeedTest2();
    247247      Console.In.ReadLine();
    248248    }
  • branches/New Persistence Exploration/Persistence/Persistence/Util.cs

    r1324 r1329  
    33using System.Text;
    44using System.Reflection;
    5 using System.Collections;
    65
    76namespace Persistence { 
     
    3130      return AutoFormat(o, recursive, visitedObjects);
    3231    }
    33     private static string AutoFormat(object o, bool recursive, Dictionary<object, int> visitedObjects) {
     32    private static string AutoFormat(object o, bool recursive, IDictionary<object, int> visitedObjects) {
    3433      string s = o as string;
    3534      if (s != null)
     
    4039      if (visitedObjects.ContainsKey(o)) {
    4140        return o.ToString();
    42       } else {
    43         visitedObjects.Add(o, 0);
    44       }     
     41      }
     42      visitedObjects.Add(o, 0);
    4543      if (o.ToString() != o.GetType().ToString()) {
    4644        return o.ToString();
     
    5856          sb.Append("=");         
    5957          if (recursive) {
    60             sb.Append(AutoFormat(((FieldInfo)mInfo).GetValue(o), true, visitedObjects));
     58            sb.Append(AutoFormat(fInfo.GetValue(o), true, visitedObjects));
    6159          } else {
    62             sb.Append(((FieldInfo)mInfo).GetValue(o));
     60            sb.Append(fInfo.GetValue(o));
    6361          }
    6462          sb.Append(", ");
Note: See TracChangeset for help on using the changeset viewer.