public static void Serialize(string solutionFilePath, SolutionFile obj, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(solutionFilePath, overwrite)) using (var textWriter = StreamWriterHelper.NewLeaveOpenAddBOM(fileStream)) { var solutionFileTextSerialializer = new SolutionFileTextSerializer(); solutionFileTextSerialializer.Serialize(textWriter, obj); } }
private static void EnsureBOMProduced() { var tempFilePath = @"C:\Temp\temp.txt"; using (var fileStream = FileStreamHelper.NewWrite(tempFilePath)) using (var writer = StreamWriterHelper.NewLeaveOpenAddBOM(fileStream)) { writer.WriteLine("Hello world! (BOM?)"); } }
public void Serialize(Stream stream, T value) { StreamWriter GetStreamWriter() { var streamWriter = this.StreamSerializerOptions.Value.AddByteOrderMark ? StreamWriterHelper.NewLeaveOpenAddBOM(stream) : StreamWriterHelper.NewLeaveOpen(stream) ; return(streamWriter); } using (var textWriter = GetStreamWriter()) { this.TextSerializer.Serialize(textWriter, value); } }