public override void Select(DynamicResources resources,
                             IValue root,
                             JsonLocationNode lastNode,
                             IValue current,
                             INodeReceiver receiver,
                             ProcessingFlags options,
                             int depth)
 {
     if (current.ValueKind == JsonValueKind.Array)
     {
         Int32 index = 0;
         foreach (var item in current.EnumerateArray())
         {
             this.TailSelect(resources, root,
                             PathGenerator.Generate(lastNode, index, options),
                             item, receiver, options, depth);
             ++index;
         }
     }
     else if (current.ValueKind == JsonValueKind.Object)
     {
         foreach (var prop in current.EnumerateObject())
         {
             this.TailSelect(resources, root,
                             PathGenerator.Generate(lastNode, prop.Name, options),
                             prop.Value, receiver, options, depth);
         }
     }
 }
Example #2
0
        public override bool TryEvaluate(DynamicResources resources,
                                         IValue current,
                                         out IValue value)
        {
            if (current.Type != JmesPathType.Array)
            {
                value = JsonConstants.Null;
                return(true);
            }

            var result = new List <IValue>();

            foreach (var item in current.EnumerateArray())
            {
                if (item.Type != JmesPathType.Null)
                {
                    IValue val;
                    if (!this.TryApplyExpressions(resources, item, out val))
                    {
                        value = JsonConstants.Null;
                        return(false);
                    }
                    if (val.Type != JmesPathType.Null)
                    {
                        result.Add(val);
                    }
                }
            }
            value = new ArrayValue(result);
            return(true);
        }
        public override void Select(DynamicResources resources,
                                    IValue root,
                                    JsonLocationNode lastNode,
                                    IValue current,
                                    INodeReceiver receiver,
                                    ProcessingFlags options,
                                    int depth)
        {
            if (depth >= resources.Options.MaxDepth)
            {
                throw new InvalidOperationException($"Maximum depth level exceeded in recursive descent selector.");
            }

            if (current.ValueKind == JsonValueKind.Array)
            {
                this.TailSelect(resources, root, lastNode, current, receiver, options, depth + 1);
                Int32 index = 0;
                foreach (var item in current.EnumerateArray())
                {
                    Select(resources, root,
                           PathGenerator.Generate(lastNode, index, options),
                           item, receiver, options, depth + 1);
                    ++index;
                }
            }
            else if (current.ValueKind == JsonValueKind.Object)
            {
                this.TailSelect(resources, root, lastNode, current, receiver, options, depth + 1);
                foreach (var prop in current.EnumerateObject())
                {
                    Select(resources, root,
                           PathGenerator.Generate(lastNode, prop.Name, options),
                           prop.Value, receiver, options, depth + 1);
                }
            }
        }