public void Serialize(Stream serializationStream, object graph)
{
if (serializationStream == null)
{
throw new System.ArgumentNullException("serializationStream");
}
if (graph == null)
{
throw new System.ArgumentNullException("graph");
}
if (_writer == null)
{
_writer = new JsonWriter();
}
var writer = new StreamWriter(serializationStream);
try
{
_writer.Init(writer);
this.WriteObject(graph);
}
catch (SerializationException ex)
{
throw ex;
}
catch (System.Exception ex)
{
throw new SerializationException("Object graph is malformed.", ex);
}
finally
{
writer.Flush();
_writer.Clear();
}
}