Esempio n. 1
0
        public JmesPathFunctionExpression(IFunctionRepository repository, string name, params JmesPathExpression[] expressions)
        {
            if (!repository.Contains(name))
            {
                throw new Exception($"Error: unknown-function, no function named {name} has been registered.");
            }

            function_ = repository[name];

            var variadic = function_.Variadic;
            var expected = function_.MinArgumentCount;
            var actual   = expressions?.Length;

            if (actual < expected || (!variadic && actual > expected))
            {
                var more   = variadic ? "or more " : "";
                var only   = variadic ? "only " : "";
                var report = actual == 0 ? "none" : $"{only}{actual}";
                var plural = expected > 1 ? "s" : "";

                throw new Exception($"Error: invalid-arity, the function {name} expects {expected} argument{plural} {more}but {report} were supplied.");
            }

            name_        = name;
            expressions_ = expressions;
        }
Esempio n. 2
0
 public bool Contains(string id)
 {
     return(_functionRepository.Contains(x => x.Id == id));
 }