Пример #1
0
        public static Result <JArrayPointer> Get(JArray jArray, JsonPointer.ReferenceToken pathPart)
        {
            if (jArray == null)
            {
                throw new ArgumentNullException(nameof(jArray));
            }
            if (pathPart == null)
            {
                throw new ArgumentNullException(nameof(pathPart));
            }

            if (pathPart != "-")
            {
                if (!int.TryParse(pathPart, out var arrayIndex))
                {
                    return(Result.Fail <JArrayPointer>($"Unable to find '{pathPart}' property of an array at '{pathPart.GetParentPointer()}'."));
                }

                if (arrayIndex < 0 || arrayIndex > jArray.Count)
                {
                    return(Result.Fail <JArrayPointer>($"Unable to find index '{arrayIndex}' in an array at '{pathPart.GetParentPointer()}'."));
                }
            }

            return(Result.Ok(new JArrayPointer(jArray, pathPart)));
        }
Пример #2
0
        public static Result <JObjectPointer> Get(JObject jObject, JsonPointer.ReferenceToken pathPart)
        {
            if (jObject == null)
            {
                throw new ArgumentNullException(nameof(jObject));
            }
            if (pathPart == null)
            {
                throw new ArgumentNullException(nameof(pathPart));
            }

            return(Result.Ok(new JObjectPointer(jObject, pathPart)));
        }
Пример #3
0
 private JArrayPointer(JArray jArray, JsonPointer.ReferenceToken pathPart)
 {
     _jArray   = jArray;
     _pathPart = pathPart;
 }
Пример #4
0
 private JObjectPointer(JObject jObject, JsonPointer.ReferenceToken pathPart)
 {
     _jObject  = jObject;
     _pathPart = pathPart;
 }