/// <summary> /// Serializes the specified object into a stream. /// </summary> /// <param name="obj">The object.</param> /// <param name="stream">The stream.</param> /// <param name="config">The configuration.</param> public static void Serialize(object obj, Stream stream, Configuration config) { try { using (StreamWriter writer = new StreamWriter(stream)) { Serializer serializer = new Serializer(obj, config); serializer.InterleaveTypeInformation = true; ReadableXmlGenerator generator = new ReadableXmlGenerator(); foreach (ISerializationToken token in serializer) { string line = generator.Format(token); writer.Write(line); } writer.Flush(); } } catch (PersistenceException) { throw; } catch (Exception e) { throw new PersistenceException("Unexpected exception during Serialization.", e); } }