示例#1
0
        internal static ShardFailure CreateShardFailure(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var f = new ShardFailure();

            if (dict.TryGetValue("shard", out var shard))
            {
                f.Shard = Convert.ToInt32(shard);
            }
            if (dict.TryGetValue("index", out var index))
            {
                f.Index = Convert.ToString(index);
            }
            if (dict.TryGetValue("node", out var node))
            {
                f.Node = Convert.ToString(node);
            }
            if (dict.TryGetValue("status", out var status))
            {
                f.Status = Convert.ToString(status);
            }
            if (dict.TryGetValue("reason", out var reason))
            {
                var cause = (ErrorCause)strategy.DeserializeObject(reason, typeof(ErrorCause));
                f.Reason = cause;
            }
            return(f);
        }
示例#2
0
        public override object DeserializeObject(object value, Type type)
        {
            if (type == typeof(DynamicBody))
            {
                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(dict == null ? null : DynamicBody.Create(dict));
            }
            if (type == typeof(ServerError))
            {
                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(ServerError.Create(dict, this));
            }
            if (type == typeof(ShardFailure))
            {
                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(ShardFailure.CreateShardFailure(dict, this));
            }
            if (type == typeof(Error))
            {
                if (value is string s)
                {
                    return new Error {
                               Reason = s
                    }
                }
                ;

                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(Error.CreateError(dict, this));
            }
            if (type == typeof(ErrorCause))
            {
                if (value is string s)
                {
                    return new ErrorCause {
                               Reason = s
                    }
                }
                ;

                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(ErrorCause.CreateErrorCause(dict, this));
            }
            return(base.DeserializeObject(value, type));
        }
    }
}