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);
         }
     }
 }
Пример #2
0
        public override bool TryEvaluate(DynamicResources resources,
                                         IValue current,
                                         out IValue value)
        {
            if (current.Type != JmesPathType.Object)
            {
                value = JsonConstants.Null;
                return(true);
            }

            var result = new List <IValue>();

            value = new ArrayValue(result);
            foreach (var item in current.EnumerateObject())
            {
                if (item.Value.Type != JmesPathType.Null)
                {
                    IValue val;
                    if (!this.TryApplyExpressions(resources, item.Value, out val))
                    {
                        return(false);
                    }
                    if (val.Type != JmesPathType.Null)
                    {
                        result.Add(val);
                    }
                }
            }
            return(true);
        }
Пример #3
0
        internal static bool IsFalse(IValue val)
        {
            var comparer = ValueEqualityComparer.Instance;

            switch (val.Type)
            {
            case JmesPathType.False:
                return(true);

            case JmesPathType.Null:
                return(true);

            case JmesPathType.Array:
                return(val.GetArrayLength() == 0);

            case JmesPathType.Object:
                return(val.EnumerateObject().MoveNext() == false);

            case JmesPathType.String:
                return(val.GetString().Length == 0);

            case JmesPathType.Number:
                return(false);

            default:
                return(false);
            }
        }
Пример #4
0
        internal static bool IsFalse(IValue val)
        {
            var comparer = ValueEqualityComparer.Instance;

            switch (val.ValueKind)
            {
            case JsonValueKind.False:
            case JsonValueKind.Null:
            case JsonValueKind.Undefined:
                return(true);

            case JsonValueKind.Array:
                return(val.GetArrayLength() == 0);

            case JsonValueKind.Object:
                return(val.EnumerateObject().MoveNext() == false);

            case JsonValueKind.String:
                return(val.GetString().Length == 0);

            case JsonValueKind.Number:
                return(false);

            default:
                return(false);
            }
        }
        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);
                }
            }
        }