/// <summary> /// Converts a string containing JSON RPC message into <see cref="Message"/>. /// </summary> /// <param name="textReader">JSON content.</param> /// <returns>A subclass of <see cref="Message"/>.</returns> /// <exception cref="ArgumentException"><paramref name="textReader"/> doesn't contain valid JSON RPC message.</exception> public static Message LoadJson(TextReader textReader) { try { return(RpcSerializer.DeserializeMessage(textReader)); } catch (Exception ex) when(ex is ArgumentException || ex is JsonException) { throw new ArgumentException("jsonContent doesn't contain valid JSON RPC message.", nameof(textReader)); } }
/// <summary> /// Gets the JSON representation of the message. /// </summary> public override string ToString() { return(RpcSerializer.SerializeMessage(this)); }
/// <summary> /// Writes the JSON RPC string into specified <see cref="TextWriter"/>. /// </summary> /// <param name="textWriter">The destination to write json content to.</param> public void WriteJson(TextWriter textWriter) { RpcSerializer.SerializeMessage(textWriter, this); }