Exemple #1
0
        private static bool IsStrict(JsonPathElement element)
        {
            switch (element.Type)
            {
            case JsonPathElementType.Root:
            case JsonPathElementType.Property:
            case JsonPathElementType.ArrayIndex:
                return(true);

            case JsonPathElementType.AnyProperty:
            case JsonPathElementType.PropertyList:
            case JsonPathElementType.AnyArrayIndex:
            case JsonPathElementType.ArrayIndexList:
            case JsonPathElementType.ArraySlice:
            case JsonPathElementType.Expression:
            case JsonPathElementType.FilterExpression:
                return(false);

            default:
                throw new ArgumentOutOfRangeException(nameof(element), element, $"Unknown JSON path element type: {element.GetType()}");
            }
        }
Exemple #2
0
        private IReadOnlyDictionary <JsonPathElement, JsonPathExpressionMatchingNode <TJsonPathExpression> > GetNonStrictNodes(JsonPathElement element)
        {
            switch (element.Type)
            {
            case JsonPathElementType.Root:
                return(Empty);

            case JsonPathElementType.Property:
            case JsonPathElementType.AnyProperty:
            case JsonPathElementType.PropertyList:
                return(_properties);

            case JsonPathElementType.ArrayIndex:
            case JsonPathElementType.AnyArrayIndex:
            case JsonPathElementType.ArrayIndexList:
            case JsonPathElementType.ArraySlice:
            case JsonPathElementType.Expression:
            case JsonPathElementType.FilterExpression:
                return(_indexes);

            case JsonPathElementType.RecursiveDescent:
                throw new ArgumentOutOfRangeException(nameof(element), element, "This should not happen: recursive descent is not allowed here");

            default:
                throw new ArgumentOutOfRangeException(nameof(element), element, $"Unknown JSON path element type: {element.GetType()}");
            }
        }
Exemple #3
0
        private static void AppendElement(this StringBuilder builder, JsonPathElement element, bool useDot)
        {
            switch (element)
            {
            case JsonPathRootElement rootElement:
                builder.AppendRoot();
                break;

            case JsonPathRecursiveDescentElement recursiveDescentElement:
                builder.AppendRecursiveDescent(recursiveDescentElement);
                break;

            case JsonPathPropertyElement propertyElement:
                builder.AppendProperty(propertyElement, useDot);
                break;

            case JsonPathAnyPropertyElement anyPropertyElement:
                builder.AppendAnyProperty(useDot);
                break;

            case JsonPathPropertyListElement propertyListElement:
                builder.AppendPropertyList(propertyListElement);
                break;

            case JsonPathArrayIndexElement arrayIndexElement:
                builder.AppendArrayIndex(arrayIndexElement);
                break;

            case JsonPathAnyArrayIndexElement anyArrayIndexElement:
                builder.AppendAnyArrayIndex();
                break;

            case JsonPathArrayIndexListElement arrayIndexListElement:
                builder.AppendArrayIndexList(arrayIndexListElement);
                break;

            case JsonPathArraySliceElement arraySliceElement:
                builder.AppendArraySlice(arraySliceElement);
                break;

            case JsonPathExpressionElement expressionElement:
                builder.AppendExpression(expressionElement);
                break;

            case JsonPathFilterExpressionElement filterExpressionElement:
                builder.AppendFilterExpression(filterExpressionElement);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(element), element, $"Unknown element type: {element.GetType()}");
            }
        }