Example #1
0
        private string Stringify(HashMap args)
        {
            if (args?.Any() != true)
            {
                return("");
            }

            var terms = new List <string>();

            foreach (var key in args.Keys)
            {
                var value = args[key];
                if (value == null)
                {
                    continue;
                }

                if (value is Var var)
                {
                    value = var.RawValue;
                }

                if (value is Range range)
                {
                    var min = Change.To <string>(range.Min);
                    var max = Change.To <string>(range.Max);
                    if (!string.IsNullOrEmpty(min))
                    {
                        terms.Add($"{key}.min={min}");
                    }
                    if (!string.IsNullOrEmpty(max))
                    {
                        terms.Add($"{key}.max={max}");
                    }
                }
                else if (!(value is string) && value is IEnumerable items)
                {
                    foreach (var item in items.Cast <object>())
                    {
                        terms.Add($"{key}[]={Change.To<string>(item)}");
                    }
                }
                else
                {
                    terms.Add($"{key}={Change.To<string>(value)}");
                }
            }
            return($"?{string.Join("&", terms)}");
        }