/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jsonObject = JObject.Load(reader); if (jsonObject == null) { return null; } var result = new WebSocketMessageMeta(); foreach (var one in jsonObject.Properties()) { if (one.Name.Equals(this.MessageBodyAlias)) { result.Body = one.Value; } else if (one.Name.Equals(this.MessageActionAlias)) { result.Action = one.Value.ToObject<string>(); } else if (one.Name.Equals(this.MessageExceptionAlias)) { result.Exception = one.Value.ToObject<ExceptionInfo>(); } else if (one.Name.Equals(this.MessageReferrerAlias)) { result.MessageReferrer = one.Value.ToObject<string>(); } } return result; }
/// <summary> /// Serializes the message. /// </summary> /// <param name="message">The message.</param> /// <returns>System.String.</returns> protected string SerializeMessage(WebSocketMessageMeta message) { return message == null ? string.Empty : message.ToJson(true, this._messageJsonConverter); }