csharp RestSharp query string maker

Dec 19, 2016 23:17 · 38 words · 1 minute read

using RestSharp.Extensions.MonoHttp;

    public static class ExQueryString
    {
        public static string GetQueryString(this object obj)
        {
            var properties = from p in obj.GetType().GetProperties()
                             where p.GetValue(obj, null) != null
                             select p.Name + "=" + HttpUtility.UrlEncode(p.GetValue(obj, null).ToString());

            return string.Join("&", properties.ToArray());
        }
    }