/// <summary>
        /// Deserializes an object from a JSON string and flattens out Error property.
        /// </summary>
        /// <param name="reader">The JSON reader.</param>
        /// <param name="objectType">The type of the object.</param>
        /// <param name="existingValue">The existing value.</param>
        /// <param name="serializer">The JSON serializer.</param>
        /// <returns></returns>
        public override object ReadJson(JsonReader reader,
            Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            JObject jObject = JObject.Load(reader);
            JProperty errorObject = jObject.Properties().FirstOrDefault(p => 
                ErrorNode.Equals(p.Name, StringComparison.OrdinalIgnoreCase));
            if (errorObject != null)
            {
                jObject = errorObject.Value as JObject;
            }
            return jObject.ToObject<CloudError>(serializer.WithoutConverter(this));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes an object from a JSON string and flattens out Error property.
        /// </summary>
        /// <param name="reader">The JSON reader.</param>
        /// <param name="objectType">The type of the object.</param>
        /// <param name="existingValue">The existing value.</param>
        /// <param name="serializer">The JSON serializer.</param>
        /// <returns></returns>
        public override object ReadJson(JsonReader reader,
            Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            JObject jObject = JObject.Load(reader);
            if (jObject.Property(ErrorNode) != null)
            {
                jObject = jObject[ErrorNode] as JObject;
            }
            return jObject.ToObject<CloudError>(serializer.WithoutConverter(this));
        }