Esempio n. 1
0
        protected void EnsureArrayOrString(JmesPathFunctionArgument argument)
        {
            var type = argument.Token?.GetTokenType();

            if (type != "array" && type != "string")
            {
                throw new Exception($"Error: invalid-type, function {Name} expects either an array or a string.");
            }
        }
Esempio n. 2
0
        private JToken EnsureOf(JmesPathFunctionArgument argument, string type)
        {
            var token     = argument.Token;
            var tokenType = token.GetTokenType();

            if (tokenType != type)
            {
                throw new Exception($"Error: invalid-type, function {Name} expects an {type}.");
            }

            return(token);
        }
Esempio n. 3
0
        protected JArray EnsureArrayOfAny(JmesPathFunctionArgument argument, params string[] types)
        {
            var array = EnsureArray(argument);

            foreach (var item in array)
            {
                if (!types.Contains(item.GetTokenType()))
                {
                    var valid = FormatAllowedDataTypes(types);
                    throw new Exception($"Error: invalid-type, function {Name} expects an array of {valid}.");
                }
            }

            return(array);
        }
Esempio n. 4
0
        protected JArray EnsureArrayOfSame(JmesPathFunctionArgument argument, params string[] types)
        {
            var array = EnsureArray(argument);

            var dataTypes = array.Select(t => t.GetTokenType()).Distinct().ToArray();

            if (dataTypes.Length > 1)
            {
                throw new Exception($"Error: invalid-type, all items in the array to the function {Name} must have the same type.");
            }

            if (types.Length > 0 && dataTypes.Length > 0 && !types.Contains(dataTypes[0]))
            {
                var valid = FormatAllowedDataTypes(types);
                throw new Exception($"Error: invalid-type, function {Name} expects an array of {valid}.");
            }

            return(array);
        }
 private static JToken Evaluate(JmesPathFunctionArgument argument)
 {
     return(argument.Token);
 }
Esempio n. 6
0
 protected JArray EnsureArrayOf(JmesPathFunctionArgument argument, string type)
 {
     return(EnsureArrayOfAny(argument, new[] { type }));
 }
Esempio n. 7
0
 protected JArray EnsureArray(JmesPathFunctionArgument argument)
 {
     return(EnsureOf(argument, "array") as JArray);
 }
Esempio n. 8
0
 protected JObject EnsureObject(JmesPathFunctionArgument argument)
 {
     return(EnsureOf(argument, "object") as JObject);
 }