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."); } }
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); }
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); }
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); }
protected JArray EnsureArrayOf(JmesPathFunctionArgument argument, string type) { return(EnsureArrayOfAny(argument, new[] { type })); }
protected JArray EnsureArray(JmesPathFunctionArgument argument) { return(EnsureOf(argument, "array") as JArray); }
protected JObject EnsureObject(JmesPathFunctionArgument argument) { return(EnsureOf(argument, "object") as JObject); }