Changeset 1566
- Timestamp:
- 04/16/09 12:58:14 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 62 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence.GUI/3.3/PersistenceConfigurationForm.cs
r1565 r1566 17 17 private readonly Dictionary<string, IFormatter> formatterTable; 18 18 private readonly Dictionary<string, bool> simpleFormatterTable; 19 private readonly Dictionary<IFormatter, string> reverseFormatterTable; 19 private readonly Dictionary<IFormatter, string> reverseFormatterTable; 20 20 private readonly Dictionary<string, Type> typeNameTable; 21 21 private readonly Dictionary<Type, string> reverseTypeNameTable; 22 22 23 public PersistenceConfigurationForm() { 23 public PersistenceConfigurationForm() { 24 24 InitializeComponent(); 25 25 formatterTable = new Dictionary<string, IFormatter>(); … … 52 52 } 53 53 54 private void UpdateDecomposerList(ListView decomposerList, Configuration config) { 54 private void UpdateDecomposerList(ListView decomposerList, Configuration config) { 55 55 decomposerList.Items.Clear(); 56 56 var availableDecomposers = new Dictionary<string, IDecomposer>(); 57 foreach (IDecomposer d in ConfigurationService.Instance.Decomposers) { 57 foreach (IDecomposer d in ConfigurationService.Instance.Decomposers) { 58 58 availableDecomposers.Add(d.GetType().VersionInvariantName(), d); 59 } 60 foreach (IDecomposer decomposer in config.Decomposers) { 61 var item = decomposerList.Items.Add(decomposer.GetType().Name); 59 } 60 foreach (IDecomposer decomposer in config.Decomposers) { 61 var item = decomposerList.Items.Add(decomposer.GetType().Name); 62 62 item.Checked = true; 63 63 item.Tag = decomposer; 64 64 availableDecomposers.Remove(decomposer.GetType().VersionInvariantName()); 65 } 65 } 66 66 foreach (KeyValuePair<string, IDecomposer> pair in availableDecomposers) { 67 67 var item = decomposerList.Items.Add(pair.Value.GetType().Name); … … 69 69 item.Tag = pair.Value; 70 70 } 71 } 71 } 72 72 73 73 private void UpdateFromConfigurationService() { 74 foreach ( IFormat format in ConfigurationService.Instance.Formats) {74 foreach (IFormat format in ConfigurationService.Instance.Formats) { 75 75 Configuration config = ConfigurationService.Instance.GetConfiguration(format); 76 76 UpdateFormatterGrid( 77 77 (DataGridView)GetControlsOnPage(format.Name, "GridView"), 78 config); 78 config); 79 79 UpdateDecomposerList( 80 80 (ListView)GetControlsOnPage(format.Name, "DecomposerList"), 81 81 config); 82 82 } 83 } 83 } 84 84 85 85 private void initializeConfigPages() { 86 configurationTabs.TabPages.Clear(); 87 foreach ( IFormat format in ConfigurationService.Instance.Formats) {86 configurationTabs.TabPages.Clear(); 87 foreach (IFormat format in ConfigurationService.Instance.Formats) { 88 88 List<IFormatter> formatters = ConfigurationService.Instance.Formatters[format.SerialDataType]; 89 89 TabPage page = new TabPage(format.Name) { … … 107 107 horizontalSplit.Panel1.Controls.Add(decomposerList); 108 108 DataGridView gridView = createGridView(); 109 verticalSplit.Panel2.Controls.Add(gridView); 109 verticalSplit.Panel2.Controls.Add(gridView); 110 110 fillDataGrid(gridView, formatters); 111 111 ListBox checkBox = new ListBox { … … 167 167 new ColumnHeader { 168 168 Name = "DecomposerColumn", Text = "Decomposers", 169 }); 169 }); 170 170 foreach (IDecomposer decomposer in ConfigurationService.Instance.Decomposers) { 171 171 var item = decomposerList.Items.Add(decomposer.GetType().Name); … … 176 176 } 177 177 178 private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) { 178 private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) { 179 179 Dictionary<string, List<string>> formatterMap = createFormatterMap(formatters); 180 foreach ( var formatterMapping in formatterMap) {180 foreach (var formatterMapping in formatterMap) { 181 181 var row = gridView.Rows[gridView.Rows.Add()]; 182 182 row.Cells["Type"].Value = formatterMapping.Key; 183 183 row.Cells["Type"].ToolTipText = formatterMapping.Key; 184 row.Cells["Active"].Value = true; 185 var comboBoxCell = (DataGridViewComboBoxCell) row.Cells["Formatter"];186 foreach ( var formatter in formatterMapping.Value) {184 row.Cells["Active"].Value = true; 185 var comboBoxCell = (DataGridViewComboBoxCell)row.Cells["Formatter"]; 186 foreach (var formatter in formatterMapping.Value) { 187 187 comboBoxCell.Items.Add(formatter); 188 } 189 comboBoxCell.Value = comboBoxCell.Items[0]; 188 } 189 comboBoxCell.Value = comboBoxCell.Items[0]; 190 190 comboBoxCell.ToolTipText = comboBoxCell.Items[0].ToString(); 191 191 if (comboBoxCell.Items.Count == 1) { 192 192 comboBoxCell.ReadOnly = true; 193 193 comboBoxCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; 194 } 194 } 195 195 } 196 196 } 197 197 198 198 private Dictionary<string, List<string>> createFormatterMap(IEnumerable<IFormatter> formatters) { 199 var formatterMap = new Dictionary<string, List<string>>(); 199 var formatterMap = new Dictionary<string, List<string>>(); 200 200 foreach (var formatter in formatters) { 201 201 string formatterName = reverseFormatterTable[formatter]; 202 string typeName = reverseTypeNameTable[formatter.SourceType]; 202 string typeName = reverseTypeNameTable[formatter.SourceType]; 203 203 if (!formatterMap.ContainsKey(typeName)) 204 204 formatterMap.Add(typeName, new List<string>()); … … 221 221 } 222 222 simpleFormatterTable[formatter.GetType().Name] = true; 223 formatterTable.Add(formatterName, formatter); 223 formatterTable.Add(formatterName, formatter); 224 224 reverseFormatterTable.Add(formatter, formatterName); 225 225 … … 244 244 } 245 245 } 246 } 246 } 247 247 248 248 void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { 249 249 UpdatePreview(); 250 } 250 } 251 251 252 252 private void decomposerList_ItemDrag(object sender, ItemDragEventArgs e) { 253 ListView decomposerList = (ListView) 253 ListView decomposerList = (ListView)sender; 254 254 decomposerList.DoDragDrop(decomposerList.SelectedItems, DragDropEffects.Move); 255 255 } 256 256 257 private void decomposerList_DragEnter(object sender, DragEventArgs e) { 258 if ( 257 private void decomposerList_DragEnter(object sender, DragEventArgs e) { 258 if (e.Data.GetDataPresent(typeof(ListView.SelectedListViewItemCollection).FullName)) { 259 259 e.Effect = DragDropEffects.Move; 260 } 260 } 261 261 } 262 262 … … 266 266 return; 267 267 } 268 Point cp = decomposerList.PointToClient(new Point(e.X, e.Y)); 269 ListViewItem targetItem = decomposerList.GetItemAt(cp.X, cp.Y); 268 Point cp = decomposerList.PointToClient(new Point(e.X, e.Y)); 269 ListViewItem targetItem = decomposerList.GetItemAt(cp.X, cp.Y); 270 270 if (targetItem == null) 271 return; 272 int targetIndex = targetItem.Index; 271 return; 272 int targetIndex = targetItem.Index; 273 273 var selectedItems = new List<ListViewItem>(decomposerList.SelectedItems.Cast<ListViewItem>()); 274 274 int i = 0; 275 foreach ( ListViewItem dragItem in selectedItems ) {275 foreach (ListViewItem dragItem in selectedItems) { 276 276 if (targetIndex == dragItem.Index) 277 277 return; 278 278 if (dragItem.Index < targetIndex) { 279 decomposerList.Items.Insert(targetIndex + 1, (ListViewItem) 279 decomposerList.Items.Insert(targetIndex + 1, (ListViewItem)dragItem.Clone()); 280 280 } else { 281 decomposerList.Items.Insert(targetIndex + i, (ListViewItem)dragItem.Clone()); 282 } 281 decomposerList.Items.Insert(targetIndex + i, (ListViewItem)dragItem.Clone()); 282 } 283 283 decomposerList.Items.Remove(dragItem); 284 284 i++; … … 288 288 289 289 private void decomposerList_Resize(object sender, EventArgs e) { 290 ListView decomposerList = (ListView)sender; 291 decomposerList.Columns["DecomposerColumn"].Width = decomposerList.Width - 4; 292 } 293 290 ListView decomposerList = (ListView)sender; 291 decomposerList.Columns["DecomposerColumn"].Width = decomposerList.Width - 4; 292 } 293 294 294 private void UpdatePreview() { 295 ListBox checkBox = (ListBox)GetActiveControl("CheckBox"); 295 ListBox checkBox = (ListBox)GetActiveControl("CheckBox"); 296 296 IFormat activeFormat = (IFormat)configurationTabs.SelectedTab.Tag; 297 if (activeFormat != null && checkBox != null 297 if (activeFormat != null && checkBox != null) { 298 298 checkBox.Items.Clear(); 299 299 Configuration activeConfig = GetActiveConfiguration(); … … 302 302 } 303 303 foreach (var decomposer in activeConfig.Decomposers) 304 checkBox.Items.Add(decomposer.GetType().Name + " (D)"); 305 } 304 checkBox.Items.Add(decomposer.GetType().Name + " (D)"); 305 } 306 306 } 307 307 … … 316 316 } else { 317 317 return null; 318 } 319 } 320 321 private Control GetControlsOnPage(string pageName, string name) { 318 } 319 } 320 321 private Control GetControlsOnPage(string pageName, string name) { 322 322 Control[] controls = configurationTabs.TabPages[pageName].Controls.Find(name, true); 323 323 if (controls.Length == 1) { … … 325 325 } else { 326 326 return null; 327 } 327 } 328 328 } 329 329 … … 358 358 359 359 private Configuration GetConfiguration(IFormat format) { 360 361 362 363 } 364 360 return GenerateConfiguration(format, 361 (DataGridView)GetControlsOnPage(format.Name, "GridView"), 362 (ListView)GetControlsOnPage(format.Name, "DecomposerList")); 363 } 364 365 365 private void updateButton_Click(object sender, EventArgs e) { 366 366 IFormat format = (IFormat)configurationTabs.SelectedTab.Tag; … … 368 368 ConfigurationService.Instance.DefineConfiguration( 369 369 GetActiveConfiguration()); 370 } 371 370 } 371 372 372 } 373 373 … … 383 383 384 384 public override Empty Format(Type o) { 385 385 return null; 386 386 } 387 387 … … 400 400 public override bool Parse(Empty o) { 401 401 return false; 402 } 403 } 402 } 403 } 404 404 405 405 [EmptyStorableClass] … … 424 424 } 425 425 426 private static void SimpleFullName(Type type, StringBuilder sb) { 426 private static void SimpleFullName(Type type, StringBuilder sb) { 427 427 if (type.IsGenericType) { 428 428 sb.Append(type.Name, 0, type.Name.LastIndexOf('`')); -
trunk/sources/HeuristicLab.Persistence.Test/NewSerializationTest.cs
r1565 r1566 24 24 [Storable] private ulong _ulong = 123456; 25 25 [Storable] private long[,] _long_array = 26 new long[,] { { 123, 456, }, {789, 123 }};26 new long[,] { { 123, 456, }, { 789, 123 } }; 27 27 [Storable] public List<int> list = new List<int>{ 1, 2, 3, 4, 5}; 28 28 } … … 176 176 public class NewSerializationTest { 177 177 178 public static void Test1() { 178 public static void Test1() { 179 179 Root r = new Root(); 180 r.selfReferences = new List<Root> { r, r};181 r.c = new Custom { r = r};180 r.selfReferences = new List<Root> { r, r }; 181 r.c = new Custom { r = r }; 182 182 r.dict.Add("one", 1); 183 183 r.dict.Add("two", 2); 184 184 r.dict.Add("three", 3); 185 185 r.myEnum = TestEnum.va1; 186 XmlGenerator.Serialize(r, "test.zip"); 187 object o = XmlParser.DeSerialize("test.zip"); 186 XmlGenerator.Serialize(r, "test.zip"); 187 object o = XmlParser.DeSerialize("test.zip"); 188 188 Console.WriteLine(ViewOnlyGenerator.Serialize(r)); 189 189 Console.WriteLine(ViewOnlyGenerator.Serialize(o)); … … 198 198 c.kvpList = new KeyValuePair<List<C>, C>(new List<C> { c }, c); 199 199 XmlGenerator.Serialize(cs, "test3.zip"); 200 object o = XmlParser.DeSerialize("test3.zip"); 200 object o = XmlParser.DeSerialize("test3.zip"); 201 201 Console.WriteLine(ViewOnlyGenerator.Serialize(cs)); 202 202 Console.WriteLine(ViewOnlyGenerator.Serialize(o)); … … 218 218 arrayListArray[2].Add(a); 219 219 XmlGenerator.Serialize(arrayListArray, "test4.zip"); 220 object o = XmlParser.DeSerialize("test4.zip"); 220 object o = XmlParser.DeSerialize("test4.zip"); 221 221 Console.WriteLine(ViewOnlyGenerator.Serialize(arrayListArray)); 222 222 Console.WriteLine(ViewOnlyGenerator.Serialize(o)); … … 224 224 225 225 public static void Test2() { 226 Manager m = new Manager(); 226 Manager m = new Manager(); 227 227 XmlGenerator.Serialize(m, "test2.zip"); 228 228 object o = XmlParser.DeSerialize("test2.zip"); 229 229 Console.WriteLine(ViewOnlyGenerator.Serialize(m)); 230 Console.WriteLine(ViewOnlyGenerator.Serialize(o)); 231 } 232 233 230 Console.WriteLine(ViewOnlyGenerator.Serialize(o)); 231 } 232 233 234 234 235 235 public static void Test5() { 236 StringDecomposerTest sdt = new StringDecomposerTest(); 236 StringDecomposerTest sdt = new StringDecomposerTest(); 237 237 XmlGenerator.Serialize(sdt, "test5.zip"); 238 238 object o = XmlParser.DeSerialize("test5.zip"); … … 267 267 268 268 public static void Test8() { 269 string[] strings = { "ora", "et", "labora" }; 269 string[] strings = { "ora", "et", "labora" }; 270 270 XmlGenerator.Serialize(strings, "test8.zip"); 271 271 object o = XmlParser.DeSerialize("test8.zip"); … … 278 278 //BinaryGenerator.Serialize(r, "test.bin"); 279 279 } 280 280 281 281 class Float { 282 282 [Storable] … … 284 284 } 285 285 286 public static void Test10() { 286 public static void Test10() { 287 287 XmlGenerator.Serialize(12.3f, "test9.zip"); 288 288 object o = XmlParser.DeSerialize("test9.zip"); … … 295 295 BasicConfigurator.Configure(); 296 296 ConfigurationService.Instance.Reset(); 297 Test1(); 297 Test1(); 298 298 Test2(); 299 299 Test3(); -
trunk/sources/HeuristicLab.Persistence.Test/SerializationTest.cs
r1454 r1566 36 36 37 37 } 38 38 39 39 class SerializationTest { 40 40 public static void Main() { -
trunk/sources/HeuristicLab.Persistence.Test/StorableAttributeTests.cs
r1555 r1566 7 7 class TestClass { 8 8 9 [Storable(Name ="TestProperty", DefaultValue=12)]9 [Storable(Name = "TestProperty", DefaultValue = 12)] 10 10 public object o; 11 11 … … 22 22 TestClass t = new TestClass(); 23 23 Dictionary<string, DataMemberAccessor> accessors = StorableAttribute.GetStorableAccessors(t); 24 foreach ( KeyValuePair<string, DataMemberAccessor> pair in accessors) {24 foreach (KeyValuePair<string, DataMemberAccessor> pair in accessors) { 25 25 Console.WriteLine(pair.Key + ": " + pair.Value); 26 26 } … … 33 33 accessors["y"].Set(0); 34 34 throw new InvalidOperationException(); 35 } catch ( KeyNotFoundException) { }35 } catch (KeyNotFoundException) { } 36 36 Console.ReadLine(); 37 37 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Configuration.cs
r1564 r1566 14 14 private readonly Dictionary<Type, IDecomposer> decomposerCache; 15 15 16 [Storable] 16 [Storable] 17 17 public IFormat Format { get; private set; } 18 18 … … 24 24 this.Format = format; 25 25 this.formatters = new Dictionary<Type, IFormatter>(); 26 foreach ( var pair in formatters) {27 if (pair.Value.SerialDataType != format.SerialDataType 26 foreach (var pair in formatters) { 27 if (pair.Value.SerialDataType != format.SerialDataType) { 28 28 throw new ArgumentException("All formatters must have the same IFormat."); 29 29 } … … 31 31 } 32 32 this.decomposers = new List<IDecomposer>(decomposers); 33 decomposerCache = new Dictionary<Type, IDecomposer>(); 33 decomposerCache = new Dictionary<Type, IDecomposer>(); 34 34 } 35 35 … … 42 42 } 43 43 44 public IFormatter GetFormatter(Type type) { 44 public IFormatter GetFormatter(Type type) { 45 45 IFormatter formatter; 46 46 formatters.TryGetValue(type, out formatter); … … 50 50 public IDecomposer GetDecomposer(Type type) { 51 51 if (decomposerCache.ContainsKey(type)) 52 return decomposerCache[type]; 52 return decomposerCache[type]; 53 53 foreach (IDecomposer d in decomposers) { 54 54 if (d.CanDecompose(type)) { … … 59 59 decomposerCache.Add(type, null); 60 60 return null; 61 } 62 } 63 61 } 62 } 63 64 64 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs
r1564 r1566 10 10 11 11 namespace HeuristicLab.Persistence.Core { 12 12 13 13 public class ConfigurationService { 14 14 … … 18 18 public List<IDecomposer> Decomposers { get; private set; } 19 19 public List<IFormat> Formats { get; private set; } 20 20 21 21 public static ConfigurationService Instance { 22 22 get { … … 54 54 } 55 55 } catch (Exception e) { 56 Logger.Warn("Could not load settings.", e); 56 Logger.Warn("Could not load settings.", e); 57 57 } 58 58 } 59 59 60 public void SaveSettings() { 60 public void SaveSettings() { 61 61 Serializer serializer = new Serializer( 62 62 customConfigurations, … … 78 78 } 79 79 80 public void Reset() { 80 public void Reset() { 81 81 customConfigurations.Clear(); 82 82 Formatters.Clear(); … … 85 85 DiscoverFrom(defaultAssembly); 86 86 foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) 87 if ( a != defaultAssembly)87 if (a != defaultAssembly) 88 88 DiscoverFrom(a); 89 89 SortDecomposers(); … … 102 102 protected void DiscoverFrom(Assembly a) { 103 103 foreach (Type t in a.GetTypes()) { 104 if (t.GetInterface(typeof 104 if (t.GetInterface(typeof(IFormatter).FullName) != null) { 105 105 try { 106 IFormatter formatter = (IFormatter) 107 if ( ! Formatters.ContainsKey(formatter.SerialDataType)) {106 IFormatter formatter = (IFormatter)Activator.CreateInstance(t, true); 107 if (!Formatters.ContainsKey(formatter.SerialDataType)) { 108 108 Formatters.Add(formatter.SerialDataType, new List<IFormatter>()); 109 109 } … … 114 114 formatter.SerialDataType.VersionInvariantName())); 115 115 } catch (MissingMethodException e) { 116 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 116 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 117 117 } catch (ArgumentException e) { 118 118 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 119 119 } 120 120 } 121 if (t.GetInterface(typeof 121 if (t.GetInterface(typeof(IDecomposer).FullName) != null) { 122 122 try { 123 Decomposers.Add((IDecomposer) 123 Decomposers.Add((IDecomposer)Activator.CreateInstance(t, true)); 124 124 Logger.Debug("discovered decomposer " + t.VersionInvariantName()); 125 125 } catch (MissingMethodException e) { 126 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 126 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 127 127 } catch (ArgumentException e) { 128 128 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); … … 136 136 format.Name, 137 137 format.SerialDataType, 138 t.VersionInvariantName())); 138 t.VersionInvariantName())); 139 139 } catch (MissingMethodException e) { 140 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 140 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 141 141 } catch (ArgumentException e) { 142 142 Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e); 143 } 143 } 144 144 } 145 145 } … … 148 148 public Configuration GetDefaultConfig(IFormat format) { 149 149 Dictionary<Type, IFormatter> formatterConfig = new Dictionary<Type, IFormatter>(); 150 foreach ( IFormatter f in Formatters[format.SerialDataType]) {151 if ( ! formatterConfig.ContainsKey(f.SourceType))150 foreach (IFormatter f in Formatters[format.SerialDataType]) { 151 if (!formatterConfig.ContainsKey(f.SourceType)) 152 152 formatterConfig.Add(f.SourceType, f); 153 153 } … … 161 161 } 162 162 163 public void DefineConfiguration(Configuration configuration) { 163 public void DefineConfiguration(Configuration configuration) { 164 164 customConfigurations[configuration.Format] = configuration; 165 165 SaveSettings(); … … 167 167 168 168 } 169 169 170 170 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/DataMemberAccessor.cs
r1542 r1566 11 11 public readonly Getter Get; 12 12 public readonly Setter Set; 13 public readonly string Name; 13 public readonly string Name; 14 14 public readonly object DefaultValue; 15 15 … … 21 21 FieldInfo fieldInfo = (FieldInfo)memberInfo; 22 22 Get = () => fieldInfo.GetValue(obj); 23 Set = value => fieldInfo.SetValue(obj, value); 23 Set = value => fieldInfo.SetValue(obj, value); 24 24 } else if (memberInfo.MemberType == MemberTypes.Property) { 25 25 PropertyInfo propertyInfo = (PropertyInfo)memberInfo; … … 29 29 } 30 30 Get = () => propertyInfo.GetValue(obj, null); 31 Set = value => propertyInfo.SetValue(obj, value, null); 31 Set = value => propertyInfo.SetValue(obj, value, null); 32 32 } else { 33 33 throw new NotSupportedException( … … 41 41 string name, object defaultValue, 42 42 Getter getter, Setter setter) { 43 Name = name; 43 Name = name; 44 44 DefaultValue = defaultValue; 45 45 Get = getter; … … 48 48 49 49 public DataMemberAccessor(object o) { 50 Name = null; 50 Name = null; 51 51 DefaultValue = null; 52 52 Get = () => o; … … 55 55 56 56 public DataMemberAccessor(object o, string name) { 57 Name = name; 57 Name = name; 58 58 DefaultValue = null; 59 59 Get = () => o; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs
r1556 r1566 4 4 using HeuristicLab.Persistence.Core.Tokens; 5 5 6 namespace HeuristicLab.Persistence.Core { 6 namespace HeuristicLab.Persistence.Core { 7 7 8 public class ParentReference { }8 public class ParentReference { } 9 9 10 10 class Midwife { 11 12 public int? Id { get; private set; } 11 12 public int? Id { get; private set; } 13 13 public bool MetaMode { get; set; } 14 14 public object Obj { get; private set; } … … 22 22 this.Obj = value; 23 23 } 24 25 public Midwife(Type type, IDecomposer decomposer, int? id) { 24 25 public Midwife(Type type, IDecomposer decomposer, int? id) { 26 26 this.type = type; 27 this.decomposer = decomposer; 27 this.decomposer = decomposer; 28 28 this.Id = id; 29 MetaMode = false; 29 MetaMode = false; 30 30 metaInfo = new List<Tag>(); 31 customValues = new List<Tag>(); 31 customValues = new List<Tag>(); 32 32 } 33 33 … … 35 35 if (Obj != null) 36 36 throw new ApplicationException("object already instantiated"); 37 Obj = decomposer.CreateInstance(type, metaInfo); 37 Obj = decomposer.CreateInstance(type, metaInfo); 38 38 } 39 39 … … 49 49 decomposer.Populate(Obj, customValues, type); 50 50 } 51 } 51 } 52 52 53 53 public class Deserializer { 54 54 55 55 private readonly Dictionary<int, object> id2obj; 56 56 private readonly Dictionary<Type, object> serializerMapping; 57 private readonly Stack<Midwife> parentStack; 57 private readonly Stack<Midwife> parentStack; 58 58 private readonly Dictionary<int, Type> typeIds; 59 59 … … 79 79 } 80 80 81 public object Deserialize(IEnumerable<ISerializationToken> tokens) { 81 public object Deserialize(IEnumerable<ISerializationToken> tokens) { 82 82 foreach (ISerializationToken token in tokens) { 83 83 Type t = token.GetType(); 84 if ( t == typeof(BeginToken)) {84 if (t == typeof(BeginToken)) { 85 85 CompositeStartHandler((BeginToken)token); 86 } else if ( t == typeof(EndToken)) {87 CompositeEndHandler((EndToken) 88 } else if ( t == typeof(PrimitiveToken)) {89 PrimitiveHandler((PrimitiveToken) 90 } else if ( t == typeof(ReferenceToken)) {91 ReferenceHandler((ReferenceToken) 86 } else if (t == typeof(EndToken)) { 87 CompositeEndHandler((EndToken)token); 88 } else if (t == typeof(PrimitiveToken)) { 89 PrimitiveHandler((PrimitiveToken)token); 90 } else if (t == typeof(ReferenceToken)) { 91 ReferenceHandler((ReferenceToken)token); 92 92 } else if (t == typeof(NullReferenceToken)) { 93 93 NullHandler((NullReferenceToken)token); … … 106 106 Type type = typeIds[(int)token.TypeId]; 107 107 IDecomposer decomposer = null; 108 if ( serializerMapping.ContainsKey(type))108 if (serializerMapping.ContainsKey(type)) 109 109 decomposer = serializerMapping[type] as IDecomposer; 110 110 if (decomposer == null) … … 124 124 private void PrimitiveHandler(PrimitiveToken token) { 125 125 Type type = typeIds[(int)token.TypeId]; 126 object value = ((IFormatter) 127 if ( token.Id != null )126 object value = ((IFormatter)serializerMapping[type]).Parse(token.SerialData); 127 if (token.Id != null) 128 128 id2obj[(int)token.Id] = value; 129 129 SetValue(token.Name, value); … … 144 144 145 145 private void MetaInfoEnd(MetaInfoEndToken token) { 146 Midwife m = parentStack.Peek(); 146 Midwife m = parentStack.Peek(); 147 147 m.MetaMode = false; 148 148 CreateInstance(m); … … 152 152 m.CreateInstance(); 153 153 if (m.Id != null) 154 id2obj.Add((int)m.Id, m.Obj); 154 id2obj.Add((int)m.Id, m.Obj); 155 155 } 156 156 157 157 private void SetValue(string name, object value) { 158 if (parentStack.Count == 0) { 158 if (parentStack.Count == 0) { 159 159 parentStack.Push(new Midwife(value)); 160 160 } else { … … 162 162 if (m.MetaMode == false && m.Obj == null) 163 163 CreateInstance(m); 164 m.AddValue(name, value); 164 m.AddValue(name, value); 165 165 } 166 166 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/EmptyStorableClassAttribute.cs
r1555 r1566 5 5 namespace HeuristicLab.Persistence.Core { 6 6 7 7 8 8 [AttributeUsage( 9 9 AttributeTargets.Class, 10 AllowMultiple =false,11 Inherited =false)]10 AllowMultiple = false, 11 Inherited = false)] 12 12 public class EmptyStorableClassAttribute : Attribute { 13 13 14 14 private static readonly Dictionary<Type, bool> emptyTypeInfo = new Dictionary<Type, bool>(); 15 public static bool IsEmptyStorable(Type type) { 15 public static bool IsEmptyStorable(Type type) { 16 16 if (emptyTypeInfo.ContainsKey(type)) 17 17 return emptyTypeInfo[type]; … … 24 24 } 25 25 int nFields = 0; 26 foreach ( MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {26 foreach (MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { 27 27 if (memberInfo.MemberType == MemberTypes.Field || 28 28 memberInfo.MemberType == MemberTypes.Property) … … 36 36 return false; 37 37 } 38 } 38 } 39 39 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/FormatBase.cs
r1564 r1566 16 16 17 17 public override bool Equals(object obj) { 18 FormatBase<SerialDataFormat> f = obj as FormatBase<SerialDataFormat>; 18 FormatBase<SerialDataFormat> f = obj as FormatBase<SerialDataFormat>; 19 19 return Equals(f); 20 20 } 21 21 22 22 } 23 23 -
trunk/sources/HeuristicLab.Persistence/3.3/Core/FormatterBase.cs
r1564 r1566 2 2 3 3 namespace HeuristicLab.Persistence.Interfaces { 4 4 5 5 public abstract class FormatterBase<Source, SerialData> : IFormatter<Source, SerialData> where SerialData : ISerialData { 6 6 … … 14 14 15 15 ISerialData IFormatter.Format(object o) { 16 return Format((Source)o); 16 return Format((Source)o); 17 17 } 18 18 … … 22 22 23 23 } 24 24 25 25 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/GeneratorBase.cs
r1564 r1566 11 11 12 12 namespace HeuristicLab.Persistence.Core { 13 13 14 14 public abstract class GeneratorBase<T> { 15 15 public T Format(ISerializationToken token) { … … 38 38 protected abstract T Format(MetaInfoBeginToken metaInfoBeginToken); 39 39 protected abstract T Format(MetaInfoEndToken metaInfoEndToken); 40 } 40 } 41 41 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r1564 r1566 16 16 17 17 public List<TypeMapping> TypeCache { 18 get { 18 get { 19 19 List<TypeMapping> result = new List<TypeMapping>(); 20 20 foreach (var pair in typeCache) { … … 30 30 result.Add(new TypeMapping(pair.Value, pair.Key.VersionInvariantName(), serializer)); 31 31 } 32 return result; 32 return result; 33 33 } 34 34 } 35 35 36 public Serializer(object obj, Configuration configuration) : 36 public Serializer(object obj, Configuration configuration) : 37 37 this(obj, configuration, "ROOT") { } 38 38 … … 40 40 this.obj = obj; 41 41 this.rootName = rootName; 42 this.configuration = configuration; 43 obj2id = new Dictionary<object, int> { {new object(), 0}};42 this.configuration = configuration; 43 obj2id = new Dictionary<object, int> { { new object(), 0 } }; 44 44 typeCache = new Dictionary<Type, int>(); 45 45 } … … 52 52 return Serialize(new DataMemberAccessor(rootName, null, () => obj, null)); 53 53 } 54 54 55 55 private IEnumerator<ISerializationToken> Serialize(DataMemberAccessor accessor) { 56 56 object value = accessor.Get(); … … 58 58 return NullReferenceEnumerator(accessor.Name); 59 59 if (obj2id.ContainsKey(value)) 60 return ReferenceEnumerator(accessor.Name, obj2id[value]); 61 if ( !typeCache.ContainsKey(value.GetType()))60 return ReferenceEnumerator(accessor.Name, obj2id[value]); 61 if (!typeCache.ContainsKey(value.GetType())) 62 62 typeCache.Add(value.GetType(), typeCache.Count); 63 63 int typeId = typeCache[value.GetType()]; 64 64 int? id = null; 65 if ( !value.GetType().IsValueType) {65 if (!value.GetType().IsValueType) { 66 66 id = obj2id.Count; 67 67 obj2id.Add(value, (int)id); … … 70 70 if (formatter != null) 71 71 return PrimitiveEnumerator(accessor.Name, typeId, formatter.Format(value), id); 72 IDecomposer decomposer = configuration.GetDecomposer(value.GetType()); 72 IDecomposer decomposer = configuration.GetDecomposer(value.GetType()); 73 73 if (decomposer != null) 74 74 return CompositeEnumerator(accessor.Name, decomposer.Decompose(value), id, typeId, decomposer.CreateMetaInfo(value)); … … 76 76 String.Format( 77 77 "No suitable method for serializing values of type \"{0}\" found.", 78 value.GetType().VersionInvariantName())); 78 value.GetType().VersionInvariantName())); 79 79 } 80 80 … … 94 94 private IEnumerator<ISerializationToken> CompositeEnumerator( 95 95 string name, IEnumerable<Tag> tags, int? id, int typeId, IEnumerable<Tag> metaInfo) { 96 yield return new BeginToken(name, typeId, id); 96 yield return new BeginToken(name, typeId, id); 97 97 bool first = true; 98 98 foreach (var tag in metaInfo) { … … 114 114 yield return it.Current; 115 115 } 116 yield return new EndToken(name, typeId, id); 116 yield return new EndToken(name, typeId, id); 117 117 } 118 118 -
trunk/sources/HeuristicLab.Persistence/3.3/Core/StorableAttribute.cs
r1555 r1566 7 7 [AttributeUsage( 8 8 AttributeTargets.Field | AttributeTargets.Property, 9 AllowMultiple =false,10 Inherited =false)]9 AllowMultiple = false, 10 Inherited = false)] 11 11 public class StorableAttribute : Attribute { 12 12 … … 19 19 BindingFlags.NonPublic | 20 20 BindingFlags.DeclaredOnly; 21 21 22 22 public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> GetStorableMembers(Type type) { 23 return GetStorableMembers(type, true); 23 return GetStorableMembers(type, true); 24 24 } 25 25 … … 27 27 GetStorableMembers(Type type, bool inherited) { 28 28 if (type.BaseType != null) 29 foreach ( var pair in GetStorableMembers(type.BaseType))29 foreach (var pair in GetStorableMembers(type.BaseType)) 30 30 yield return pair; 31 31 foreach (MemberInfo memberInfo in type.GetMembers(instanceMembers)) { 32 foreach (object attribute in memberInfo.GetCustomAttributes(false)) { 32 foreach (object attribute in memberInfo.GetCustomAttributes(false)) { 33 33 StorableAttribute storableAttribute = 34 34 attribute as StorableAttribute; 35 35 if (storableAttribute != null) { 36 yield return new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo); 36 yield return new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo); 37 37 } 38 38 } 39 } 39 } 40 40 } 41 41 … … 46 46 storableAccessors.Add(pair.Value.Name, 47 47 new DataMemberAccessor(pair.Value, pair.Key, obj)); 48 } 48 } 49 49 return storableAccessors; 50 } 50 } 51 51 } 52 52 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tag.cs
r1553 r1566 5 5 public class Tag { 6 6 public string Name { get; private set; } 7 public object Value { get; set; } 7 public object Value { get; set; } 8 8 9 9 public Tag(string name, object value) { -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/MetaInfoEndToken.cs
r1556 r1566 4 4 5 5 public class MetaInfoEndToken : ISerializationToken { } 6 6 7 7 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/NulLReferenceToken.cs
r1556 r1566 2 2 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 5 public class NullReferenceToken : SerializationTokenBase { 6 6 public NullReferenceToken(string name) : base(name) { } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/PrimitiveToken.cs
r1564 r1566 2 2 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 5 public class PrimitiveToken : SerializationTokenBase { 4 5 public class PrimitiveToken : SerializationTokenBase { 6 6 public readonly int TypeId; 7 7 public readonly int? Id; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/ReferenceToken.cs
r1556 r1566 2 2 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 5 public class ReferenceToken : SerializationTokenBase { 4 5 public class ReferenceToken : SerializationTokenBase { 6 6 public readonly int Id; 7 7 public ReferenceToken(string name, int id) -
trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeExtensions.cs
r1555 r1566 3 3 4 4 namespace HeuristicLab.Persistence.Core { 5 5 6 6 public static class TypeExtensions { 7 7 … … 12 12 } 13 13 14 } 15 14 } 15 16 16 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeMapping.cs
r1542 r1566 6 6 public readonly int Id; 7 7 public readonly string TypeName; 8 public readonly string Serializer; 8 public readonly string Serializer; 9 9 public TypeMapping(int id, string typeName, string serializer) { 10 10 Id = id; … … 16 16 {"id", Id}, 17 17 {"typeName", TypeName}, 18 {"serializer", Serializer}}; 18 {"serializer", Serializer}}; 19 19 } 20 } 20 } 21 21 22 22 } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeStringBuilder.cs
r1555 r1566 7 7 8 8 internal static void BuildDeclaringTypeChain(Type type, StringBuilder sb) { 9 if ( type.DeclaringType != null) {9 if (type.DeclaringType != null) { 10 10 BuildDeclaringTypeChain(type.DeclaringType, sb); 11 11 sb.Append(type.DeclaringType.Name).Append('+'); … … 20 20 sb.Append("["); 21 21 Type[] args = type.GetGenericArguments(); 22 for ( int i = 0; i<args.Length; i++) {22 for (int i = 0; i < args.Length; i++) { 23 23 sb.Append("["); 24 24 BuildVersionInvariantName(args[i], sb); … … 28 28 sb.Remove(sb.Length - 1, 1); 29 29 sb.Append("]"); 30 } 30 } 31 31 sb.Append(", ").Append(type.Assembly.GetName().Name); 32 32 } 33 33 34 34 } 35 35 36 36 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/ArrayDecomposer.cs
r1563 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Decomposers { 7 7 8 8 [EmptyStorableClass] 9 9 public class ArrayDecomposer : IDecomposer { … … 20 20 Array a = (Array)obj; 21 21 yield return new Tag("rank", a.Rank); 22 for (int i = 0; i < a.Rank; i++) { 22 for (int i = 0; i < a.Rank; i++) { 23 23 yield return new Tag("length_" + i, a.GetLength(i)); 24 24 } 25 for (int i = 0; i < a.Rank; i++) { 25 for (int i = 0; i < a.Rank; i++) { 26 26 yield return new Tag("lowerBound_" + i, a.GetLowerBound(i)); 27 } 27 } 28 28 } 29 29 30 30 public IEnumerable<Tag> Decompose(object array) { 31 Array a = (Array)array; 31 Array a = (Array)array; 32 32 int[] lengths = new int[a.Rank]; 33 33 int[] lowerBounds = new int[a.Rank]; … … 67 67 lowerBounds[i] = (int)e.Current.Value; 68 68 } 69 return Array.CreateInstance(t.GetElementType(), lengths, lowerBounds); 69 return Array.CreateInstance(t.GetElementType(), lengths, lowerBounds); 70 70 } 71 71 72 public void Populate(object instance, IEnumerable<Tag> elements, Type t) { 72 public void Populate(object instance, IEnumerable<Tag> elements, Type t) { 73 73 Array a = (Array)instance; 74 74 int[] lengths = new int[a.Rank]; … … 79 79 for (int i = 0; i < a.Rank; i++) { 80 80 lowerBounds[i] = a.GetLowerBound(i); 81 } 81 } 82 82 int[] positions = (int[])lowerBounds.Clone(); 83 83 IEnumerator<Tag> e = elements.GetEnumerator(); … … 86 86 a.SetValue(e.Current.Value, currentPositions); 87 87 positions[0] += 1; 88 for (int i = 0; i < a.Rank -1; i++) {89 if (positions[i] >= lengths[i] +lowerBounds[i]) {88 for (int i = 0; i < a.Rank - 1; i++) { 89 if (positions[i] >= lengths[i] + lowerBounds[i]) { 90 90 positions[i] = lowerBounds[i]; 91 91 positions[i + 1] += 1; … … 97 97 } 98 98 } 99 99 100 100 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/DictionaryDecomposer.cs
r1563 r1566 5 5 using System.Collections.Generic; 6 6 7 namespace HeuristicLab.Persistence.Default.Decomposers { 8 7 namespace HeuristicLab.Persistence.Default.Decomposers { 8 9 9 [EmptyStorableClass] 10 10 public class DictionaryDecomposer : IDecomposer { … … 16 16 17 17 public bool CanDecompose(Type type) { 18 return type.GetInterface(typeof(IDictionary).FullName) != null; 18 return type.GetInterface(typeof(IDictionary).FullName) != null; 19 19 } 20 20 … … 24 24 25 25 public IEnumerable<Tag> Decompose(object o) { 26 IDictionary dict = (IDictionary)o; 27 foreach ( 26 IDictionary dict = (IDictionary)o; 27 foreach (DictionaryEntry entry in dict) { 28 28 yield return new Tag("key", entry.Key); 29 29 yield return new Tag("value", entry.Value); … … 43 43 Tag value = iter.Current; 44 44 dict.Add(key.Value, value.Value); 45 } 45 } 46 46 } 47 47 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumDecomposer.cs
r1563 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Decomposers { 7 7 8 8 [EmptyStorableClass] 9 9 public class EnumDecomposer : IDecomposer { … … 30 30 return Enum.Parse(t, (string)it.Current.Value); 31 31 } 32 33 public void Populate(object instance, IEnumerable<Tag> elements, Type t) { 32 33 public void Populate(object instance, IEnumerable<Tag> elements, Type t) { 34 34 } 35 35 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumerableDecomposer.cs
r1563 r1566 6 6 using System.Collections.Generic; 7 7 8 namespace HeuristicLab.Persistence.Default.Decomposers { 8 namespace HeuristicLab.Persistence.Default.Decomposers { 9 9 10 10 [EmptyStorableClass] -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/KeyValuePairDecomposer.cs
r1563 r1566 7 7 8 8 namespace HeuristicLab.Persistence.Default.Decomposers { 9 9 10 10 [EmptyStorableClass] 11 11 public class KeyValuePairDecomposer : IDecomposer { … … 18 18 public bool CanDecompose(Type type) { 19 19 return type.IsGenericType && 20 type.GetGenericTypeDefinition() == 21 typeof 20 type.GetGenericTypeDefinition() == 21 typeof(KeyValuePair<int, int>).GetGenericTypeDefinition(); 22 22 } 23 23 … … 38 38 public void Populate(object instance, IEnumerable<Tag> o, Type t) { 39 39 IEnumerator<Tag> iter = o.GetEnumerator(); 40 iter.MoveNext(); 40 iter.MoveNext(); 41 41 t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) 42 42 .Single(fi => fi.Name == "key").SetValue(instance, iter.Current.Value); 43 43 iter.MoveNext(); 44 44 t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) 45 .Single(fi => fi.Name == "value").SetValue(instance, iter.Current.Value); 45 .Single(fi => fi.Name == "value").SetValue(instance, iter.Current.Value); 46 46 } 47 47 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/StorableDecomposer.cs
r1563 r1566 34 34 } 35 35 36 public void Populate(object instance, IEnumerable<Tag> objects, Type type) { 37 var memberDict = new Dictionary<string, Tag>(); 38 IEnumerator<Tag> iter = objects.GetEnumerator(); 36 public void Populate(object instance, IEnumerable<Tag> objects, Type type) { 37 var memberDict = new Dictionary<string, Tag>(); 38 IEnumerator<Tag> iter = objects.GetEnumerator(); 39 39 while (iter.MoveNext()) { 40 40 memberDict.Add(iter.Current.Name, iter.Current); 41 } 41 } 42 42 foreach (var mapping in StorableAttribute.GetStorableAccessors(instance)) { 43 43 if (memberDict.ContainsKey(mapping.Key)) { 44 mapping.Value.Set(memberDict[mapping.Key].Value); 44 mapping.Value.Set(memberDict[mapping.Key].Value); 45 45 } else if (mapping.Value.DefaultValue != null) { 46 46 mapping.Value.Set(mapping.Value.DefaultValue); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/TypeDecomposer.cs
r1563 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Decomposers { 7 7 8 8 [EmptyStorableClass] 9 9 public class TypeDecomposer : IDecomposer { … … 14 14 15 15 public bool CanDecompose(Type type) { 16 return type == typeof 16 return type == typeof(Type) || 17 17 type.VersionInvariantName() == "System.RuntimeType, mscorlib"; 18 18 } … … 30 30 return Type.GetType((string)typeName.Value); 31 31 } 32 return null; 32 return null; 33 33 } 34 34 35 public void Populate(object instance, IEnumerable<Tag> objects, Type type) { 35 public void Populate(object instance, IEnumerable<Tag> objects, Type type) { 36 36 } 37 37 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/X2StringDecomposer.cs
r1563 r1566 9 9 namespace HeuristicLab.Persistence.Default.Decomposers { 10 10 11 public class Number2StringConverter { 11 public class Number2StringConverter { 12 12 13 13 private static readonly List<Type> numberTypes = … … 27 27 }; 28 28 29 private static readonly Dictionary<Type, MethodInfo> numberParsers; 29 private static readonly Dictionary<Type, MethodInfo> numberParsers; 30 30 31 31 static Number2StringConverter() { 32 32 numberParsers = new Dictionary<Type, MethodInfo>(); 33 foreach ( var type in numberTypes) {33 foreach (var type in numberTypes) { 34 34 numberParsers[type] = type 35 35 .GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, 36 null, new[] { typeof (string)}, null);36 null, new[] { typeof(string) }, null); 37 37 } 38 38 } … … 43 43 44 44 public string Format(object obj) { 45 if (obj.GetType() == typeof(float)) 45 if (obj.GetType() == typeof(float)) 46 46 return ((float)obj).ToString("r", CultureInfo.InvariantCulture); 47 47 if (obj.GetType() == typeof(double)) … … 51 51 return obj.ToString(); 52 52 } 53 53 54 54 public object Parse(string stringValue, Type type) { 55 55 return numberParsers[type] 56 56 .Invoke(null, 57 57 BindingFlags.Static | BindingFlags.PutRefDispProperty, 58 null, new[] { stringValue}, CultureInfo.InvariantCulture);59 } 60 61 } 58 null, new[] { stringValue }, CultureInfo.InvariantCulture); 59 } 60 61 } 62 62 63 63 [EmptyStorableClass] … … 88 88 } 89 89 90 public void Populate(object instance, IEnumerable<Tag> tags, Type type) { 91 } 92 93 } 90 public void Populate(object instance, IEnumerable<Tag> tags, Type type) { 91 } 92 93 } 94 94 95 95 [EmptyStorableClass] … … 99 99 get { return 200; } 100 100 } 101 101 102 102 private static readonly Number2StringConverter numberConverter = 103 new Number2StringConverter(); 103 new Number2StringConverter(); 104 104 105 105 public bool CanDecompose(Type type) { 106 106 return 107 (type.IsArray || type == typeof 107 (type.IsArray || type == typeof(Array)) && 108 108 numberConverter.CanDecompose(type.GetElementType()); 109 109 } … … 146 146 var tagIter = metaInfo.GetEnumerator(); 147 147 tagIter.MoveNext(); 148 var valueIter = ((string) 149 .Split(new[] { ';'}, StringSplitOptions.RemoveEmptyEntries)148 var valueIter = ((string)tagIter.Current.Value) 149 .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) 150 150 .GetEnumerator(); 151 151 valueIter.MoveNext(); 152 int rank = int.Parse((string) valueIter.Current);152 int rank = int.Parse((string)valueIter.Current); 153 153 int[] lengths = new int[rank]; 154 int[] lowerBounds = new int[rank]; 154 int[] lowerBounds = new int[rank]; 155 155 for (int i = 0; i < rank; i++) { 156 156 valueIter.MoveNext(); 157 lengths[i] = int.Parse((string) valueIter.Current);158 } 157 lengths[i] = int.Parse((string)valueIter.Current); 158 } 159 159 for (int i = 0; i < rank; i++) { 160 160 valueIter.MoveNext(); 161 lowerBounds[i] = int.Parse((string) valueIter.Current);161 lowerBounds[i] = int.Parse((string)valueIter.Current); 162 162 } 163 163 Type elementType = type.GetElementType(); 164 164 Array a = Array.CreateInstance(elementType, lengths, lowerBounds); 165 int[] positions = (int[]) 165 int[] positions = (int[])lowerBounds.Clone(); 166 166 while (valueIter.MoveNext()) { 167 167 a.SetValue( 168 numberConverter.Parse((string)valueIter.Current, elementType), 168 numberConverter.Parse((string)valueIter.Current, elementType), 169 169 positions); 170 170 positions[0] += 1; 171 for ( int i = 0; i<rank-1; i++) {171 for (int i = 0; i < rank - 1; i++) { 172 172 if (positions[i] >= lengths[i] + lowerBounds[i]) { 173 173 positions[i + 1] += 1; … … 195 195 private static readonly Number2StringConverter numberConverter = 196 196 new Number2StringConverter(); 197 197 198 198 private static readonly Dictionary<Type, Type> interfaceCache = new Dictionary<Type, Type>(); 199 199 … … 212 212 return null; 213 213 } 214 214 215 215 public bool ImplementsGenericEnumerable(Type type) { 216 216 return GetGenericEnumerableInterface(type) != null; … … 225 225 BindingFlags.NonPublic | 226 226 BindingFlags.Instance, 227 null, Type.EmptyTypes, null) != null; 227 null, Type.EmptyTypes, null) != null; 228 228 } 229 229 … … 240 240 public IEnumerable<Tag> Decompose(object obj) { 241 241 Type type = obj.GetType(); 242 Type enumerable = GetGenericEnumerableInterface(type); 243 InterfaceMapping iMap = obj.GetType().GetInterfaceMap(enumerable); 242 Type enumerable = GetGenericEnumerableInterface(type); 243 InterfaceMapping iMap = obj.GetType().GetInterfaceMap(enumerable); 244 244 MethodInfo getEnumeratorMethod = 245 245 iMap.TargetMethods[ … … 247 247 iMap.InterfaceMethods, 248 248 enumerable.GetMethod("GetEnumerator"))]; 249 object[] empty = new object[] { };249 object[] empty = new object[] { }; 250 250 object genericEnumerator = getEnumeratorMethod.Invoke(obj, empty); 251 251 MethodInfo moveNextMethod = genericEnumerator.GetType().GetMethod("MoveNext"); 252 252 PropertyInfo currentProperty = genericEnumerator.GetType().GetProperty("Current"); 253 253 StringBuilder sb = new StringBuilder(); 254 while ( (bool)moveNextMethod.Invoke(genericEnumerator, empty))254 while ((bool)moveNextMethod.Invoke(genericEnumerator, empty)) 255 255 sb.Append( 256 256 numberConverter.Format( … … 265 265 public void Populate(object instance, IEnumerable<Tag> tags, Type type) { 266 266 Type enumerable = GetGenericEnumerableInterface(type); 267 Type elementType = enumerable.GetGenericArguments()[0]; 268 MethodInfo addMethod = type.GetMethod("Add"); 267 Type elementType = enumerable.GetGenericArguments()[0]; 268 MethodInfo addMethod = type.GetMethod("Add"); 269 269 var tagEnumerator = tags.GetEnumerator(); 270 270 tagEnumerator.MoveNext(); 271 string[] stringValues = ((string) 272 .Split(new[] { ';'}, StringSplitOptions.RemoveEmptyEntries);271 string[] stringValues = ((string)tagEnumerator.Current.Value) 272 .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); 273 273 foreach (var value in stringValues) { 274 addMethod.Invoke(instance, new[] { numberConverter.Parse(value, elementType)});274 addMethod.Invoke(instance, new[] { numberConverter.Parse(value, elementType) }); 275 275 } 276 276 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/ViewOnly/ViewOnlyFormat.cs
r1564 r1566 17 17 18 18 public class ViewOnlyFormat : FormatBase<String> { 19 public override string Name { get { return "ViewOnly"; } } 19 public override string Name { get { return "ViewOnly"; } } 20 20 } 21 21 … … 47 47 [EmptyStorableClass] 48 48 public class Float2ViewFormatter : ValueType2ViewFormatterBase<float> { } 49 49 50 50 public class ViewOnlyGenerator : GeneratorBase<string> { 51 51 … … 58 58 isSepReq = false; 59 59 this.showRefs = showRefs; 60 } 60 } 61 61 62 62 protected override string Format(BeginToken beginToken) { 63 StringBuilder sb = new StringBuilder(); 63 StringBuilder sb = new StringBuilder(); 64 64 if (isSepReq) 65 65 sb.Append(", "); 66 if ( ! string.IsNullOrEmpty(beginToken.Name)) {66 if (!string.IsNullOrEmpty(beginToken.Name)) { 67 67 sb.Append(beginToken.Name); 68 if ( beginToken.Id != null && showRefs) {68 if (beginToken.Id != null && showRefs) { 69 69 sb.Append('['); 70 70 sb.Append(beginToken.Id); 71 71 sb.Append(']'); 72 } 72 } 73 73 } 74 74 sb.Append("("); … … 78 78 79 79 protected override string Format(EndToken endToken) { 80 isSepReq = true; 80 isSepReq = true; 81 81 return ")"; 82 82 } 83 83 84 84 protected override string Format(PrimitiveToken primitiveToken) { 85 StringBuilder sb = new StringBuilder(); 85 StringBuilder sb = new StringBuilder(); 86 86 if (isSepReq) 87 87 sb.Append(", "); 88 if ( ! string.IsNullOrEmpty(primitiveToken.Name)) {88 if (!string.IsNullOrEmpty(primitiveToken.Name)) { 89 89 sb.Append(primitiveToken.Name); 90 if ( primitiveToken.Id != null && showRefs) {90 if (primitiveToken.Id != null && showRefs) { 91 91 sb.Append('['); 92 92 sb.Append(primitiveToken.Id); … … 96 96 } 97 97 sb.Append(((String)primitiveToken.SerialData).Data); 98 isSepReq = true; 99 return sb.ToString(); 98 isSepReq = true; 99 return sb.ToString(); 100 100 } 101 101 … … 104 104 if (isSepReq) 105 105 sb.Append(", "); 106 if ( ! string.IsNullOrEmpty(referenceToken.Name)) {106 if (!string.IsNullOrEmpty(referenceToken.Name)) { 107 107 sb.Append(referenceToken.Name); 108 108 sb.Append('='); … … 111 111 sb.Append(referenceToken.Id); 112 112 sb.Append('}'); 113 isSepReq = true; 113 isSepReq = true; 114 114 return sb.ToString(); 115 115 } … … 141 141 142 142 public static string Serialize(object o, Configuration configuration) { 143 Serializer s = new Serializer(o, configuration); 143 Serializer s = new Serializer(o, configuration); 144 144 ViewOnlyGenerator generator = new ViewOnlyGenerator(); 145 145 StringBuilder sb = new StringBuilder(); 146 146 foreach (ISerializationToken token in s) { 147 sb.Append(generator.Format(token)); 147 sb.Append(generator.Format(token)); 148 148 } 149 149 return sb.ToString(); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleArray2XmlFormatters.cs
r1564 r1566 4 4 5 5 namespace HeuristicLab.Persistence.Default.Xml.Compact { 6 6 7 7 public abstract class DoubleArray2XmlFormatterBase<T> : NumberArray2XmlFormatterBase<T> { 8 8 9 9 protected override string FormatValue(object o) { 10 10 return ((double)o).ToString("r", CultureInfo.InvariantCulture); … … 24 24 25 25 [EmptyStorableClass] 26 public class Double3DArray2XmlFormatter : DoubleArray2XmlFormatterBase<double[, ,]> { }27 26 public class Double3DArray2XmlFormatter : DoubleArray2XmlFormatterBase<double[, ,]> { } 27 28 28 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleList2XmlFormatter.cs
r1564 r1566 8 8 9 9 [EmptyStorableClass] 10 public class DoubleList2XmlFormatter : NumberEnumeration2XmlFormatterBase<List<double>> { 10 public class DoubleList2XmlFormatter : NumberEnumeration2XmlFormatterBase<List<double>> { 11 11 12 12 protected override void Add(IEnumerable enumeration, object o) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntArray2XmlFormatters.cs
r1564 r1566 3 3 4 4 namespace HeuristicLab.Persistence.Default.Xml.Compact { 5 6 public abstract class IntArray2XmlFormatterBase<T> : NumberArray2XmlFormatterBase<T> { 5 6 public abstract class IntArray2XmlFormatterBase<T> : NumberArray2XmlFormatterBase<T> { 7 7 8 8 protected override string FormatValue(object o) { … … 22 22 23 23 [EmptyStorableClass] 24 public class Int3DArray2XmlFormatter : IntArray2XmlFormatterBase<int[, ,]> { }25 24 public class Int3DArray2XmlFormatter : IntArray2XmlFormatterBase<int[, ,]> { } 25 26 26 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntList2XmlFormatter.cs
r1564 r1566 8 8 [EmptyStorableClass] 9 9 public class IntList2XmlFormatter : NumberEnumeration2XmlFormatterBase<List<int>> { 10 10 11 11 protected override void Add(IEnumerable enumeration, object o) { 12 12 ((List<int>)enumeration).Add((int)o); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlFormatterBase.cs
r1564 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Xml.Compact { 7 7 8 8 public abstract class NumberArray2XmlFormatterBase<T> : FormatterBase<T, XmlString> { 9 9 … … 30 30 } 31 31 int[] positions = (int[])lowerBounds.Clone(); 32 while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) { 32 while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) { 33 33 sb.Append(Separator); 34 34 sb.Append(FormatValue(a.GetValue(positions))); … … 42 42 } 43 43 } 44 } 44 } 45 45 return new XmlString(sb.ToString()); 46 46 } … … 80 80 } 81 81 } 82 82 83 83 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlFormatterBase.cs
r1564 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Xml.Compact { 7 7 8 8 public abstract class NumberEnumeration2XmlFormatterBase<T> : FormatterBase<T, XmlString> where T : IEnumerable { 9 9 … … 32 32 } 33 33 } 34 34 35 35 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Bool2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Bool2XmlFormatter : SimpleNumber2XmlFormatterBase<bool> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Byte2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Byte2XmlFormatter : SimpleNumber2XmlFormatterBase<byte> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DateTime2XmlFormatter.cs
r1564 r1566 6 6 7 7 [EmptyStorableClass] 8 public class DateTime2XmlFormatter : FormatterBase<DateTime, XmlString> { 9 8 public class DateTime2XmlFormatter : FormatterBase<DateTime, XmlString> { 9 10 10 public override XmlString Format(DateTime dt) { 11 return new XmlString(dt.Ticks.ToString()); 11 return new XmlString(dt.Ticks.ToString()); 12 12 } 13 13 … … 18 18 } 19 19 20 20 21 21 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Decimal2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Decimal2XmlFormatter : DecimalNumber2XmlFormatterBase<decimal> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DecimalNumber2XmlFormatterBase.cs
r1564 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 public abstract class DecimalNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> { 10 10 11 11 private static MethodInfo ToStringMethod = typeof(T) 12 12 .GetMethod( … … 30 30 return new XmlString((string)ToStringMethod.Invoke(t, new object[] { "r", CultureInfo.InvariantCulture })); 31 31 } 32 public override T Parse(XmlString x) { 32 public override T Parse(XmlString x) { 33 33 return (T)ParseMethod.Invoke(null, new object[] { x.Data, CultureInfo.InvariantCulture }); 34 34 } 35 } 35 } 36 36 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Double2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Double2XmlFormatter : DecimalNumber2XmlFormatterBase<double> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Float2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Float2XmlFormatter : DecimalNumber2XmlFormatterBase<float> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Int2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 9 [EmptyStorableClass] 10 10 public class Int2XmlFormatter : SimpleNumber2XmlFormatterBase<int> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Long2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 9 [EmptyStorableClass] 10 10 public class Long2XmlFormatter : SimpleNumber2XmlFormatterBase<long> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SByte2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Sbyte2XmlFormatter : SimpleNumber2XmlFormatterBase<sbyte> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Short2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Short2XmlFormatter : SimpleNumber2XmlFormatterBase<short> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SimpleNumber2XmlFormatterBase.cs
r1564 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 9 public abstract class SimpleNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> { … … 22 22 } 23 23 public override T Parse(XmlString x) { 24 return (T)ParseMethod.Invoke(null, new[] { x.Data }); 24 return (T)ParseMethod.Invoke(null, new[] { x.Data }); 25 25 } 26 } 26 } 27 27 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs
r1564 r1566 9 9 [EmptyStorableClass] 10 10 public class String2XmlFormatter : FormatterBase<string, XmlString> { 11 11 12 12 public override XmlString Format(string s) { 13 13 StringBuilder sb = new StringBuilder(); … … 15 15 sb.Append(s.Replace("]]>", "]]]]><![CDATA[>")); 16 16 sb.Append("]]>"); 17 return new XmlString(sb.ToString()); 17 return new XmlString(sb.ToString()); 18 18 } 19 19 … … 22 22 public override string Parse(XmlString x) { 23 23 StringBuilder sb = new StringBuilder(); 24 foreach (string s in x.Data.Split(separators, 24 foreach (string s in x.Data.Split(separators, 25 25 StringSplitOptions.RemoveEmptyEntries)) { 26 26 sb.Append(s); … … 28 28 return sb.ToString(); 29 29 } 30 } 30 } 31 31 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/UInt2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class UInt2XmlFormatter : SimpleNumber2XmlFormatterBase<uint> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/ULong2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 public class ULong2XmlFormatter : SimpleNumber2XmlFormatterBase<ulong> { } 11 10 public class ULong2XmlFormatter : SimpleNumber2XmlFormatterBase<ulong> { } 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/UShort2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class UShort2XmlFormatter : SimpleNumber2XmlFormatterBase<ushort> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlFormat.cs
r1564 r1566 6 6 [EmptyStorableClass] 7 7 public class XmlFormat : FormatBase<XmlString> { 8 public override string Name { get { return "XML"; } } 8 public override string Name { get { return "XML"; } } 9 9 } 10 10 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r1564 r1566 21 21 public const string METAINFO = "METAINFO"; 22 22 } 23 23 24 24 public class XmlGenerator : GeneratorBase<string> { 25 25 26 26 private int depth; 27 27 … … 45 45 if (type == NodeType.End) 46 46 sb.Append('/'); 47 sb.Append(name); 47 sb.Append(name); 48 48 foreach (var attribute in attributes) { 49 49 if (attribute.Value != null && !string.IsNullOrEmpty(attribute.Value.ToString())) { … … 58 58 sb.Append('/'); 59 59 sb.Append(">"); 60 return sb.ToString(); 60 return sb.ToString(); 61 61 } 62 62 … … 65 65 } 66 66 67 protected override string Format(BeginToken beginToken) { 67 protected override string Format(BeginToken beginToken) { 68 68 var attributes = new Dictionary<string, object> { 69 69 {"name", beginToken.Name}, … … 76 76 } 77 77 78 protected override string Format(EndToken endToken) { 78 protected override string Format(EndToken endToken) { 79 79 depth -= 1; 80 80 return Prefix + "</" + XmlStrings.COMPOSITE + ">\r\n"; 81 81 } 82 82 83 protected override string Format(PrimitiveToken dataToken) { 83 protected override string Format(PrimitiveToken dataToken) { 84 84 var attributes = 85 85 new Dictionary<string, object> { … … 89 89 return Prefix + 90 90 FormatNode(XmlStrings.PRIMITIVE, attributes, NodeType.Start) + 91 ((XmlString)dataToken.SerialData).Data + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 91 ((XmlString)dataToken.SerialData).Data + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 92 92 } 93 93 94 protected override string Format(ReferenceToken refToken) { 94 protected override string Format(ReferenceToken refToken) { 95 95 var attributes = new Dictionary<string, object> { 96 96 {"ref", refToken.Id}, 97 {"name", refToken.Name}}; 98 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 97 {"name", refToken.Name}}; 98 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 99 99 } 100 100 101 protected override string Format(NullReferenceToken nullRefToken) { 101 protected override string Format(NullReferenceToken nullRefToken) { 102 102 var attributes = new Dictionary<string, object>{ 103 {"name", nullRefToken.Name}}; 103 {"name", nullRefToken.Name}}; 104 104 return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\r\n"; 105 105 } … … 127 127 } 128 128 129 public static void Serialize(object o, string filename) { 129 public static void Serialize(object o, string filename) { 130 130 Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 131 131 } … … 135 135 XmlGenerator generator = new XmlGenerator(); 136 136 ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename)); 137 zipStream.SetLevel(9); 138 zipStream.PutNextEntry(new ZipEntry("data.xml")); 137 zipStream.SetLevel(9); 138 zipStream.PutNextEntry(new ZipEntry("data.xml")); 139 139 StreamWriter writer = new StreamWriter(zipStream); 140 ILog logger = Logger.GetDefaultLogger(); 140 ILog logger = Logger.GetDefaultLogger(); 141 141 foreach (ISerializationToken token in serializer) { 142 142 string line = generator.Format(token); … … 151 151 logger.Debug(line); 152 152 } 153 writer.Flush(); 154 zipStream.Close(); 153 writer.Flush(); 154 zipStream.Close(); 155 155 } 156 156 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r1564 r1566 19 19 public XmlParser(TextReader input) { 20 20 XmlReaderSettings settings = new XmlReaderSettings { 21 22 23 24 21 ConformanceLevel = ConformanceLevel.Document, 22 IgnoreWhitespace = true, 23 IgnoreComments = true 24 }; 25 25 reader = XmlReader.Create(input, settings); 26 26 handlers = new Dictionary<string, Handler> { … … 66 66 67 67 private IEnumerator<ISerializationToken> ParseComposite() { 68 string name = reader.GetAttribute("name"); 68 string name = reader.GetAttribute("name"); 69 69 string idString = reader.GetAttribute("id"); 70 70 int? id = null; … … 104 104 var typeCache = new List<TypeMapping>(); 105 105 XmlReader xmlReader = XmlReader.Create(reader); 106 while ( xmlReader.Read()) {106 while (xmlReader.Read()) { 107 107 if (xmlReader.Name == XmlStrings.TYPE) { 108 108 typeCache.Add(new TypeMapping( … … 116 116 117 117 public static object DeSerialize(string filename) { 118 ZipFile zipFile = new ZipFile(filename); 118 ZipFile zipFile = new ZipFile(filename); 119 119 Deserializer deSerializer = new Deserializer( 120 120 ParseTypeCache( … … 123 123 XmlParser parser = new XmlParser( 124 124 new StreamReader(zipFile.GetInputStream(zipFile.GetEntry("data.xml")))); 125 return deSerializer.Deserialize(parser); 125 return deSerializer.Deserialize(parser); 126 126 } 127 } 127 } 128 128 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlString.cs
r1564 r1566 3 3 4 4 namespace HeuristicLab.Persistence.Default.Xml { 5 5 6 6 public class XmlString : ISerialData { 7 7 -
trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLabPersistencePlugin.cs
r1534 r1566 6 6 [PluginFile(Filename = "HeuristicLab.Persistence-3.3.dll", Filetype = PluginFileType.Assembly)] 7 7 [Dependency(Dependency = "HeuristicLab.Tracing-3.2")] 8 public class HeuristicLabPersistencePlugin : PluginBase { }8 public class HeuristicLabPersistencePlugin : PluginBase { } 9 9 10 10 } -
trunk/sources/HeuristicLab.Persistence/3.3/Interfaces/IDecomposer.cs
r1553 r1566 47 47 /// </summary> 48 48 void Populate(object instance, IEnumerable<Tag> tags, Type type); 49 } 49 } 50 50 51 51 } -
trunk/sources/HeuristicLab.Persistence/3.3/Interfaces/IFormatter.cs
r1564 r1566 12 12 Type SourceType { get; } 13 13 ISerialData Format(object o); 14 object Parse(ISerialData o); 14 object Parse(ISerialData o); 15 15 } 16 16 … … 23 23 SerialData Format(Source o); 24 24 Source Parse(SerialData t); 25 } 26 25 } 26 27 27 } -
trunk/sources/HeuristicLab.Persistence/3.3/Interfaces/ISerialData.cs
r1564 r1566 3 3 namespace HeuristicLab.Persistence.Interfaces { 4 4 5 5 6 6 /// <summary> 7 7 /// Marker interface for serialized values generated and parsed by -
trunk/sources/HeuristicLab.Persistence/3.3/Interfaces/ISerializationToken.cs
r1562 r1566 6 6 /// deserializer, parser and generator. 7 7 /// </summary> 8 public interface ISerializationToken { }9 8 public interface ISerializationToken { } 9 10 10 }
Note: See TracChangeset
for help on using the changeset viewer.