コード例 #1
0
        public override JsonElement Execute(JsonElement input)
        {
            if (input.IsNullOrUndefined())
            {
                return(JsonElementFactory.CreateNull());
            }

            List <JsonElement> args = Arguments.Select(x => x.Execute(input)).ToList();

            input = CalledOnExpression.Execute(input);

            if (input.ValueKind == JsonValueKind.String && input.TryExecuteStringMethod(MethodName, args, out JsonElement result1))
            {
                return(result1);
            }

            if (input.ValueKind == JsonValueKind.Array && input.TryExecuteArrayMethod(MethodName, args, out JsonElement result2))
            {
                return(result2);
            }

            return(JsonElementFactory.CreateNull());
        }
コード例 #2
0
        internal void EnsureMethodNameIsValid()
        {
            if (CalledOnExpression is PropertyFilterSubExpression || CalledOnExpression is ArrayAccessFilterSubExpression ||
                CalledOnExpression is MethodCallFilterSubExpression || CalledOnExpression is StringConstantFilterSubExpression)
            {
                if (!_validMethodNames.Contains(MethodName))
                {
                    throw new UnrecognizedMethodNameException($"Method name {MethodName} not recognized. Please see: https://github.com/stanac/JsonPathway for supported methods");
                }
                return;
            }

            if (_validMethodNames.Contains(MethodName))
            {
                throw new UnrecognizedMethodNameException($"Method name {MethodName} is valid but not supported on expression of type: {CalledOnExpression.GetType()}. Please see: https://github.com/stanac/JsonPathway for supported methods");
            }

            throw new UnrecognizedMethodNameException($"Method name {MethodName} not recognized on expression of type: {CalledOnExpression.GetType()}. Please see: https://github.com/stanac/JsonPathway for supported methods");
        }