Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1447 for branches


Ignore:
Timestamp:
03/27/09 13:45:33 (16 years ago)
Author:
epitzer
Message:

refactoring and code clean up. (#9999)

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

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/Core/ConfigurationService.cs

    r1425 r1447  
    11using System;
    2 using System.Collections.Specialized;
    32using System.IO;
    4 using System.Linq;
    53using System.Collections.Generic;
    64using System.Reflection;
  • branches/New Persistence Exploration/Persistence/Persistence/Core/DataMemberAccessor.cs

    r1435 r1447  
    11using System;
    22using System.Reflection;
    3 using HeuristicLab.Persistence.Core;
    43
    5 namespace HeuristicLab.Persistence {
     4namespace HeuristicLab.Persistence.Core {
    65
    76  public delegate object Getter();
     
    6463
    6564    public override string ToString() {
    66       return String.Format("DataMember({0}, {2}, {3}, {4})",
     65      return String.Format("DataMember({0}, {1}, {2}, {3})",
    6766        Name,
    6867        DefaultValue ?? "<null>",
  • branches/New Persistence Exploration/Persistence/Persistence/Core/DeSerializer.cs

    r1437 r1447  
    1818
    1919    public void AddValue(string name, object value, List<Thunk> finalFixes) {
    20       Tag t = new Tag(name, value);
    21       t.finalFixes = finalFixes;
     20      Tag t = new Tag(name, value) {finalFixes = finalFixes};
    2221      customValues.Add(t);
    2322    }
     
    4847
    4948    private Dictionary<Type, object> createSerializers(IEnumerable<TypeMapping> typeCache) {
    50       var serializerMapping = new Dictionary<Type, object>();
     49      var map = new Dictionary<Type, object>();
    5150      foreach (var typeMapping in typeCache) {
    5251        Type type = Type.GetType(typeMapping.TypeName);
     
    5453        if (typeMapping.Serializer != null) {
    5554          Type serializerType = Type.GetType(typeMapping.Serializer);
    56           serializerMapping.Add(type, Activator.CreateInstance(serializerType, true));
     55          map.Add(type, Activator.CreateInstance(serializerType, true));
    5756        }
    5857      }
    59       return serializerMapping;
     58      return map;
    6059    }
    6160
     
    9392          "No suitable method for deserialization of type \"{0}\" found.",
    9493          type.VersionInvariantName()));
    95       object instance = decomposer.CreateInstance(type);
    96       if (instance == null)
    97         instance = new ParentReference();
     94      object instance =
     95        decomposer.CreateInstance(type) ??
     96        new ParentReference();
    9897      parentStack.Push(new CompositeObject(instance));             
    9998      if ( token.Id != null )
     
    110109          "No suitable method for deserialization of type \"{0}\" found.",
    111110          type.VersionInvariantName()));
    112       CompositeObject customComposite = (CompositeObject)parentStack.Pop();
     111      CompositeObject customComposite = parentStack.Pop();
    113112      object deserializedObject =         
    114113        decomposer.Populate(customComposite.Obj, customComposite.customValues, type);
  • branches/New Persistence Exploration/Persistence/Persistence/Core/Serializer.cs

    r1425 r1447  
    55
    66namespace HeuristicLab.Persistence.Core {
    7 
    8   public struct TypeMapping {
    9     public readonly int Id;
    10     public readonly string TypeName;
    11     public readonly string Serializer;   
    12     public TypeMapping(int id, string typeName, string serializer) {
    13       Id = id;
    14       TypeName = typeName;
    15       Serializer = serializer;
    16     }
    17     public Dictionary<string, object> GetDict() {
    18       return new Dictionary<string, object> {
    19         {"id", Id},
    20         {"typeName", TypeName},
    21         {"serializer", Serializer}};                                           
    22     }
    23   }
    247
    258  public class Serializer : IEnumerable<ISerializationToken> {
  • branches/New Persistence Exploration/Persistence/Persistence/Core/TypeStringBuilder.cs

    r1422 r1447  
    11using System;
    2 using System.Collections.Specialized;
    3 using System.IO;
    4 using System.Linq;
    5 using System.Collections.Generic;
    6 using System.Reflection;
    72using System.Text;
    8 using HeuristicLab.Persistence.Default.Xml;
    9 using HeuristicLab.Persistence.Interfaces;
    103
    114namespace HeuristicLab.Persistence.Core {
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/ArrayDecomposer.cs

    r1438 r1447  
    11using System;
    2 using System.Collections;
    32using HeuristicLab.Persistence.Core;
    43using HeuristicLab.Persistence.Interfaces;
     
    4948      while (e.MoveNext()) {
    5049        int[] currentPositions = positions;
    51         e.Current.SafeSet((value) => a.SetValue(value, currentPositions));       
     50        e.Current.SafeSet(value => a.SetValue(value, currentPositions));       
    5251        positions[0] += 1;
    5352        for (int i = 0; i < rank-1; i++) {
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/DictionaryDecomposer.cs

    r1434 r1447  
    1212    object key;
    1313    object value;
    14     IDictionary dict;
     14    readonly IDictionary dict;
    1515
    1616    public DictionaryAdder(IDictionary dict) {
     
    2020    }
    2121
    22     public void SetKey(object value) {
    23       key = value;
     22    public void SetKey(object v) {
     23      key = v;
    2424      keyIsSet = true;
    2525      check();
    2626    }
    2727
    28     public void SetValue(object value) {
    29       this.value = value;
     28    public void SetValue(object v) {
     29      value = v;
    3030      valueIsSet = true;
    3131      check();
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/EnumerableDecomposer.cs

    r1435 r1447  
    88namespace HeuristicLab.Persistence.Default.Decomposers {
    99
    10   public class EnumerableCache {   
    11 
    12     List<object> values;
     10  public class EnumerableCache {
     11    readonly List<object> values;
    1312    int nSet;
    1413    int count;
    15     object enumerable;
    16     MethodInfo addMethod;
     14    readonly object enumerable;
     15    readonly MethodInfo addMethod;
    1716
    1817    public EnumerableCache(object enumerable, MethodInfo addMethod) {     
     
    2625      int index = values.Count;     
    2726      values.Add(new object());
    28       return (v) => Set(index, v);
     27      return v => Set(index, v);
    2928    }
    3029
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/KeyValuePairDecomposer.cs

    r1434 r1447  
    11using System;
    22using System.Linq;
    3 using System.Collections;
    43using System.Collections.Generic;
    54using HeuristicLab.Persistence.Core;
     
    3231      FieldInfo keyFieldInfo =
    3332        t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
    34         .Single((fi) => fi.Name == "key");
     33        .Single(fi => fi.Name == "key");
    3534      FieldInfo valueFieldInfo =
    3635        t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
    37         .Single((fi) => fi.Name == "value");
    38       iter.Current.SafeSet((value) => keyFieldInfo.SetValue(instance, value));     
     36        .Single(fi => fi.Name == "value");
     37      iter.Current.SafeSet(value => keyFieldInfo.SetValue(instance, value));     
    3938      iter.MoveNext();
    40       iter.Current.SafeSet((value) => valueFieldInfo.SetValue(instance, value));
     39      iter.Current.SafeSet(value => valueFieldInfo.SetValue(instance, value));
    4140      return instance;
    4241    }   
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/StorableDecomposer.cs

    r1434 r1447  
    22using System.Collections.Generic;
    33using System.Linq;
    4 using System.Text;
    54using HeuristicLab.Persistence.Interfaces;
    65using HeuristicLab.Persistence.Core;
    7 using System.Collections;
    86
    97namespace HeuristicLab.Persistence.Default.Decomposers {
     
    3129      IEnumerator<Tag> iter = objects.GetEnumerator();     
    3230      while (iter.MoveNext()) {
    33         memberDict.Add((string)iter.Current.Name, iter.Current);
     31        memberDict.Add(iter.Current.Name, iter.Current);
    3432      }     
    3533      foreach (var mapping in StorableAttribute.GetAutostorableAccessors(instance)) {
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/TypeDecomposer.cs

    r1425 r1447  
    11using System;
    2 using System.Collections;
    32using HeuristicLab.Persistence.Core;
    43using HeuristicLab.Persistence.Interfaces;
  • branches/New Persistence Exploration/Persistence/Persistence/Default/ViewOnly/ViewOnlyFormat.cs

    r1429 r1447  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    43using System.Text;
    54using HeuristicLab.Persistence.Interfaces;
     
    6968
    7069    private bool isSepReq;
    71     private bool showRefs;
     70    private readonly bool showRefs;
    7271
    7372    public ViewOnlyGenerator() : this(false) { }
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Xml/XmlGenerator.cs

    r1437 r1447  
    2222      if (type == typeof(BeginToken))
    2323        return Format((BeginToken)token);
    24       else if (type == typeof(EndToken))
     24      if (type == typeof(EndToken))
    2525        return Format((EndToken)token);
    26       else if (type == typeof(PrimitiveToken))
     26      if (type == typeof(PrimitiveToken))
    2727        return Format((PrimitiveToken)token);
    28       else if (type == typeof(ReferenceToken))
     28      if (type == typeof(ReferenceToken))
    2929        return Format((ReferenceToken)token);
    30       else if (type == typeof(NullReferenceToken))
     30      if (type == typeof(NullReferenceToken))
    3131        return Format((NullReferenceToken)token);
    32       else
    33         throw new ApplicationException("Invalid token of type " + type.FullName);
     32      throw new ApplicationException("Invalid token of type " + type.FullName);
    3433    }
    3534    protected abstract T Format(BeginToken beginToken);
  • branches/New Persistence Exploration/Persistence/Persistence/HeuristicLab.Persistence-3.3.csproj

    r1429 r1447  
    5757  <ItemGroup>
    5858    <Compile Include="Core\Configuration.cs" />
     59    <Compile Include="Core\TypeMapping.cs" />
    5960    <Compile Include="Core\TypeStringBuilder.cs" />
    6061    <Compile Include="Default\Decomposers\EnumerableDecomposer.cs" />
     
    8081    <Compile Include="HeuristicLabPersistencePlugin.cs" />
    8182    <Compile Include="Core\DeSerializer.cs" />
     83    <Compile Include="Core\Tag.cs" />
    8284    <Compile Include="Interfaces\IDecomposer.cs" />
    8385    <Compile Include="Interfaces\IFormatter.cs" />
  • branches/New Persistence Exploration/Persistence/Persistence/Interfaces/IDecomposer.cs

    r1437 r1447  
    11using System;
    2 using System.Collections;
    32using System.Collections.Generic;
    43using HeuristicLab.Persistence.Core;
    54
    65namespace HeuristicLab.Persistence.Interfaces {
    7 
    8   public class Tag {
    9     public List<Thunk> finalFixes;
    10     public string Name { get; private set; }
    11     public object Value;     
    12 
    13     public Tag(string name, object value) {
    14       this.Name = name;
    15       this.Value = value;
    16     }
    17     public Tag(object value) {
    18       this.Name = null;
    19       this.Value = value;
    20     }
    21     public void SafeSet(Setter setter) {
    22       if ( Value != null && Value.GetType() == typeof(ParentReference))
    23         finalFixes.Add(() => setter(Value));
    24       else
    25         setter(Value);
    26     }
    27   }
    286
    297  public interface IDecomposer {
Note: See TracChangeset for help on using the changeset viewer.