public static void SerializeObject( this IXmlSerializerInternal serializer, Stream stream, object instance, Encoding encoding, Formatting formatting, ISerializeOptions options) { options = options.WithNewSerializationState(); StreamWriter streamWriter = null; try { streamWriter = new StreamWriter(stream, encoding ?? Encoding.UTF8); var xmlWriter = new XSerializerXmlTextWriter(streamWriter, options) { Formatting = formatting }; serializer.SerializeObject(xmlWriter, instance, options); xmlWriter.Flush(); } finally { if (streamWriter != null) { streamWriter.Flush(); } } }
public static void SerializeObject( this IXmlSerializerInternal serializer, TextWriter writer, object instance, Formatting formatting, ISerializeOptions options) { options = options.WithNewSerializationState(); var xmlWriter = new XSerializerXmlTextWriter(writer, options) { Formatting = formatting }; serializer.SerializeObject(xmlWriter, instance, options); xmlWriter.Flush(); }