Skip to content

Instantly share code, notes, and snippets.

@danieleli
Created March 24, 2015 20:06
Show Gist options
  • Save danieleli/362ea7832ad106c3c70e to your computer and use it in GitHub Desktop.
Save danieleli/362ea7832ad106c3c70e to your computer and use it in GitHub Desktop.
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