Example #1
0
        private IEnumerable <string> GetPairs(bool encodeSpaceAsPlus)
        {
            foreach (var key in _orderedKeys)
            {
                var val = this[key];
                if (val == null)
                {
                    continue;
                }

                if (val is string || !(val is IEnumerable))
                {
                    yield return(key + "=" + Url.EncodeQueryParamValue(val, encodeSpaceAsPlus));
                }
                else
                {
                    // if value is IEnumerable (other than string), break it into multiple
                    // values with same param name, i.e. x=1&x2&x=3
                    // https://github.com/tmenier/Flurl/issues/15
                    foreach (var subval in val as IEnumerable)
                    {
                        if (subval == null)
                        {
                            continue;
                        }

                        yield return(key + "=" + Url.EncodeQueryParamValue(subval, encodeSpaceAsPlus));
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Returns the string ("name=value") representation of the query parameter.
 /// </summary>
 /// <param name="encodeSpaceAsPlus">Indicates whether to encode space characters with "+" instead of "%20".</param>
 /// <returns></returns>
 public string ToString(bool encodeSpaceAsPlus)
 {
     if (Value is IEnumerable && !(Value is string))
     {
         return(string.Join("&",
                            from v in (Value as IEnumerable).Cast <object>()
                            where v != null
                            let encoded = Url.EncodeQueryParamValue(v, encodeSpaceAsPlus)
                                          select $"{Name}={encoded}"));
     }
     else
     {
         var encoded = _encodedValue ?? Url.EncodeQueryParamValue(_value, encodeSpaceAsPlus);
         return($"{Name}={encoded}");
     }
 }
Example #3
0
 private static string BuildPair(string name, object value, bool encodeSpaceAsPlus)
 {
     return((value == null) ? name : $"{name}={Url.EncodeQueryParamValue(value, encodeSpaceAsPlus)}");
 }