public static string ToJsonString(this IEnumerable <EventSet> events) { using (var stream = new MemoryStream()) { using (IPayloadWriter writer = new JsonPayloadWriter(stream)) { writer.Write(string.Empty, events); } stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } }
public static void WriteToStream(this IEnumerable <EventSet> events, Stream stream, PayloadFormat format) { IPayloadWriter writer = null; if (format == PayloadFormat.Binary) { writer = new BinaryPayloadWriter(stream); } else { writer = new JsonPayloadWriter(stream); } using (writer) { writer.Write(string.Empty, events); } }