- Timestamp:
- 02/01/11 12:40:12 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r4068 r5403 126 126 } 127 127 requiredFiles = new List<string>(files.Keys); 128 } 129 130 public IEnumerable<Type> SerializedTypes { 131 get { 132 return typeCache.Keys; 133 } 128 134 } 129 135 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r4068 r5403 405 405 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies) { 406 406 try { 407 using (StreamWriter writer = new StreamWriter(new GZipStream(stream, CompressionMode.Compress))) { 408 Serializer serializer = new Serializer(obj, config); 409 serializer.InterleaveTypeInformation = true; 410 XmlGenerator generator = new XmlGenerator(); 411 foreach (ISerializationToken token in serializer) { 412 string line = generator.Format(token); 413 writer.Write(line); 414 } 415 writer.Flush(); 407 Serializer serializer = new Serializer(obj, config); 408 Serialize(stream, serializer); 409 } catch (PersistenceException) { 410 throw; 411 } catch (Exception e) { 412 throw new PersistenceException("Unexpected exception during Serialization.", e); 413 } 414 } 415 416 /// <summary> 417 /// Serializes the specified object into a stream. 418 /// </summary> 419 /// <param name="obj">The object.</param> 420 /// <param name="stream">The stream.</param> 421 /// <param name="config">The configuration.</param> 422 /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param> 423 /// <param name="types">The list of all serialized types.</param> 424 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, out IEnumerable<Type> types) { 425 try { 426 Serializer serializer = new Serializer(obj, config); 427 Serialize(stream, serializer); 428 types = serializer.SerializedTypes; 429 } catch (PersistenceException) { 430 throw; 431 } catch (Exception e) { 432 throw new PersistenceException("Unexpected exception during Serialization.", e); 433 } 434 } 435 436 private static void Serialize(Stream stream, Serializer serializer) { 437 using (StreamWriter writer = new StreamWriter(new GZipStream(stream, CompressionMode.Compress))) { 438 serializer.InterleaveTypeInformation = true; 439 XmlGenerator generator = new XmlGenerator(); 440 foreach (ISerializationToken token in serializer) { 441 string line = generator.Format(token); 442 writer.Write(line); 416 443 } 417 } 418 catch (PersistenceException) { 419 throw; 420 } 421 catch (Exception e) { 422 throw new PersistenceException("Unexpected exception during Serialization.", e); 444 writer.Flush(); 423 445 } 424 446 } -
trunk/sources/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r5324 r5403 1228 1228 } 1229 1229 1230 [TestMethod] 1231 public void TestTypeCacheExport() { 1232 var test = new List<List<int>>(); 1233 test.Add(new List<int>() { 1, 2, 3 }); 1234 IEnumerable<Type> types; 1235 using (var stream = new MemoryStream()) { 1236 XmlGenerator.Serialize(test, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types); 1237 } 1238 List<Type> t = new List<Type>(types); 1239 // Assert.IsTrue(t.Contains(typeof(int))); not serialized as an int list is directly transformed into a string 1240 Assert.IsTrue(t.Contains(typeof(List<int>))); 1241 Assert.IsTrue(t.Contains(typeof(List<List<int>>))); 1242 Assert.AreEqual(t.Count, 2); 1243 } 1244 1230 1245 1231 1246
Note: See TracChangeset
for help on using the changeset viewer.