- Timestamp:
- 03/27/09 13:45:33 (16 years ago)
- 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 1 1 using System; 2 using System.Collections.Specialized;3 2 using System.IO; 4 using System.Linq;5 3 using System.Collections.Generic; 6 4 using System.Reflection; -
branches/New Persistence Exploration/Persistence/Persistence/Core/DataMemberAccessor.cs
r1435 r1447 1 1 using System; 2 2 using System.Reflection; 3 using HeuristicLab.Persistence.Core;4 3 5 namespace HeuristicLab.Persistence {4 namespace HeuristicLab.Persistence.Core { 6 5 7 6 public delegate object Getter(); … … 64 63 65 64 public override string ToString() { 66 return String.Format("DataMember({0}, { 2}, {3}, {4})",65 return String.Format("DataMember({0}, {1}, {2}, {3})", 67 66 Name, 68 67 DefaultValue ?? "<null>", -
branches/New Persistence Exploration/Persistence/Persistence/Core/DeSerializer.cs
r1437 r1447 18 18 19 19 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}; 22 21 customValues.Add(t); 23 22 } … … 48 47 49 48 private Dictionary<Type, object> createSerializers(IEnumerable<TypeMapping> typeCache) { 50 var serializerMapping= new Dictionary<Type, object>();49 var map = new Dictionary<Type, object>(); 51 50 foreach (var typeMapping in typeCache) { 52 51 Type type = Type.GetType(typeMapping.TypeName); … … 54 53 if (typeMapping.Serializer != null) { 55 54 Type serializerType = Type.GetType(typeMapping.Serializer); 56 serializerMapping.Add(type, Activator.CreateInstance(serializerType, true));55 map.Add(type, Activator.CreateInstance(serializerType, true)); 57 56 } 58 57 } 59 return serializerMapping;58 return map; 60 59 } 61 60 … … 93 92 "No suitable method for deserialization of type \"{0}\" found.", 94 93 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(); 98 97 parentStack.Push(new CompositeObject(instance)); 99 98 if ( token.Id != null ) … … 110 109 "No suitable method for deserialization of type \"{0}\" found.", 111 110 type.VersionInvariantName())); 112 CompositeObject customComposite = (CompositeObject)parentStack.Pop();111 CompositeObject customComposite = parentStack.Pop(); 113 112 object deserializedObject = 114 113 decomposer.Populate(customComposite.Obj, customComposite.customValues, type); -
branches/New Persistence Exploration/Persistence/Persistence/Core/Serializer.cs
r1425 r1447 5 5 6 6 namespace 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 }24 7 25 8 public class Serializer : IEnumerable<ISerializationToken> { -
branches/New Persistence Exploration/Persistence/Persistence/Core/TypeStringBuilder.cs
r1422 r1447 1 1 using System; 2 using System.Collections.Specialized;3 using System.IO;4 using System.Linq;5 using System.Collections.Generic;6 using System.Reflection;7 2 using System.Text; 8 using HeuristicLab.Persistence.Default.Xml;9 using HeuristicLab.Persistence.Interfaces;10 3 11 4 namespace HeuristicLab.Persistence.Core { -
branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/ArrayDecomposer.cs
r1438 r1447 1 1 using System; 2 using System.Collections;3 2 using HeuristicLab.Persistence.Core; 4 3 using HeuristicLab.Persistence.Interfaces; … … 49 48 while (e.MoveNext()) { 50 49 int[] currentPositions = positions; 51 e.Current.SafeSet( (value)=> a.SetValue(value, currentPositions));50 e.Current.SafeSet(value => a.SetValue(value, currentPositions)); 52 51 positions[0] += 1; 53 52 for (int i = 0; i < rank-1; i++) { -
branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/DictionaryDecomposer.cs
r1434 r1447 12 12 object key; 13 13 object value; 14 IDictionary dict;14 readonly IDictionary dict; 15 15 16 16 public DictionaryAdder(IDictionary dict) { … … 20 20 } 21 21 22 public void SetKey(object v alue) {23 key = v alue;22 public void SetKey(object v) { 23 key = v; 24 24 keyIsSet = true; 25 25 check(); 26 26 } 27 27 28 public void SetValue(object v alue) {29 this.value = value;28 public void SetValue(object v) { 29 value = v; 30 30 valueIsSet = true; 31 31 check(); -
branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/EnumerableDecomposer.cs
r1435 r1447 8 8 namespace HeuristicLab.Persistence.Default.Decomposers { 9 9 10 public class EnumerableCache { 11 12 List<object> values; 10 public class EnumerableCache { 11 readonly List<object> values; 13 12 int nSet; 14 13 int count; 15 object enumerable;16 MethodInfo addMethod;14 readonly object enumerable; 15 readonly MethodInfo addMethod; 17 16 18 17 public EnumerableCache(object enumerable, MethodInfo addMethod) { … … 26 25 int index = values.Count; 27 26 values.Add(new object()); 28 return (v)=> Set(index, v);27 return v => Set(index, v); 29 28 } 30 29 -
branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/KeyValuePairDecomposer.cs
r1434 r1447 1 1 using System; 2 2 using System.Linq; 3 using System.Collections;4 3 using System.Collections.Generic; 5 4 using HeuristicLab.Persistence.Core; … … 32 31 FieldInfo keyFieldInfo = 33 32 t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) 34 .Single( (fi)=> fi.Name == "key");33 .Single(fi => fi.Name == "key"); 35 34 FieldInfo valueFieldInfo = 36 35 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)); 39 38 iter.MoveNext(); 40 iter.Current.SafeSet( (value)=> valueFieldInfo.SetValue(instance, value));39 iter.Current.SafeSet(value => valueFieldInfo.SetValue(instance, value)); 41 40 return instance; 42 41 } -
branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/StorableDecomposer.cs
r1434 r1447 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Text;5 4 using HeuristicLab.Persistence.Interfaces; 6 5 using HeuristicLab.Persistence.Core; 7 using System.Collections;8 6 9 7 namespace HeuristicLab.Persistence.Default.Decomposers { … … 31 29 IEnumerator<Tag> iter = objects.GetEnumerator(); 32 30 while (iter.MoveNext()) { 33 memberDict.Add( (string)iter.Current.Name, iter.Current);31 memberDict.Add(iter.Current.Name, iter.Current); 34 32 } 35 33 foreach (var mapping in StorableAttribute.GetAutostorableAccessors(instance)) { -
branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/TypeDecomposer.cs
r1425 r1447 1 1 using System; 2 using System.Collections;3 2 using HeuristicLab.Persistence.Core; 4 3 using HeuristicLab.Persistence.Interfaces; -
branches/New Persistence Exploration/Persistence/Persistence/Default/ViewOnly/ViewOnlyFormat.cs
r1429 r1447 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq;4 3 using System.Text; 5 4 using HeuristicLab.Persistence.Interfaces; … … 69 68 70 69 private bool isSepReq; 71 private bool showRefs;70 private readonly bool showRefs; 72 71 73 72 public ViewOnlyGenerator() : this(false) { } -
branches/New Persistence Exploration/Persistence/Persistence/Default/Xml/XmlGenerator.cs
r1437 r1447 22 22 if (type == typeof(BeginToken)) 23 23 return Format((BeginToken)token); 24 elseif (type == typeof(EndToken))24 if (type == typeof(EndToken)) 25 25 return Format((EndToken)token); 26 elseif (type == typeof(PrimitiveToken))26 if (type == typeof(PrimitiveToken)) 27 27 return Format((PrimitiveToken)token); 28 elseif (type == typeof(ReferenceToken))28 if (type == typeof(ReferenceToken)) 29 29 return Format((ReferenceToken)token); 30 elseif (type == typeof(NullReferenceToken))30 if (type == typeof(NullReferenceToken)) 31 31 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); 34 33 } 35 34 protected abstract T Format(BeginToken beginToken); -
branches/New Persistence Exploration/Persistence/Persistence/HeuristicLab.Persistence-3.3.csproj
r1429 r1447 57 57 <ItemGroup> 58 58 <Compile Include="Core\Configuration.cs" /> 59 <Compile Include="Core\TypeMapping.cs" /> 59 60 <Compile Include="Core\TypeStringBuilder.cs" /> 60 61 <Compile Include="Default\Decomposers\EnumerableDecomposer.cs" /> … … 80 81 <Compile Include="HeuristicLabPersistencePlugin.cs" /> 81 82 <Compile Include="Core\DeSerializer.cs" /> 83 <Compile Include="Core\Tag.cs" /> 82 84 <Compile Include="Interfaces\IDecomposer.cs" /> 83 85 <Compile Include="Interfaces\IFormatter.cs" /> -
branches/New Persistence Exploration/Persistence/Persistence/Interfaces/IDecomposer.cs
r1437 r1447 1 1 using System; 2 using System.Collections;3 2 using System.Collections.Generic; 4 3 using HeuristicLab.Persistence.Core; 5 4 6 5 namespace 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 else25 setter(Value);26 }27 }28 6 29 7 public interface IDecomposer {
Note: See TracChangeset
for help on using the changeset viewer.