Ejemplo n.º 1
0
        /// <summary>
        /// Deserializes a Statement from a json string.
        /// </summary>
        /// <param name="jsonString">The json representation of a statement.</param>
        /// <returns>The deserialized statement</returns>
        public static Statement FromJson(string jsonString)
        {
            if (string.IsNullOrWhiteSpace(jsonString))
            {
                throw new ArgumentNullException(nameof(jsonString));
            }

            try
            {
                return(JsonConvert.DeserializeObject <Statement>(jsonString, JsonSerializerSettingsFactory.CreateSettings()));
            }
            catch (JsonReaderException ex)
            {
                throw new ArgumentException(
                          "Unable to deserialize passed string, check inner exception for more details",
                          nameof(jsonString),
                          ex);
            }
            catch (JsonSerializationException ex)
            {
                throw new ArgumentException(
                          "The passed Json string is not a valid Statement. Please check inner exception for more details",
                          nameof(jsonString),
                          ex);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the json representation of the Statement object.
 /// </summary>
 /// <param name="prettyPrint">If set to true, the json will be with an indented formatting.</param>
 /// <returns>The json representation of the statement.</returns>
 public string ToJson(bool prettyPrint = false)
 {
     return(JsonConvert.SerializeObject(this, prettyPrint ? Formatting.Indented : Formatting.None, JsonSerializerSettingsFactory.CreateSettings()));
 }