Created
March 24, 2015 20:06
-
-
Save danieleli/362ea7832ad106c3c70e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ReportExtensions | |
{ | |
public static string Serialize(this Report report) | |
{ | |
var stream = SerializeToStream(report); | |
var finalString = ReadStream(stream); | |
return finalString; | |
} | |
private static string ReadStream(MemoryStream stream) | |
{ | |
stream.Position = 0; | |
var reader = new StreamReader(stream, Encoding.Default); | |
var finalString = reader.ReadToEnd(); | |
return finalString; | |
} | |
private static MemoryStream SerializeToStream(Report report) | |
{ | |
var stream = new MemoryStream(); | |
var serializer = new XmlSerializer(typeof (Report)); | |
serializer.Serialize(stream, report); | |
return stream; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment