using System.Collections.Generic;
public static void Main()
Console.WriteLine(SerializeAsFormData(new SampleType() { PropInt = 1, PropString = "hola", PropDateTime=DateTime.UtcNow }));
public int PropInt { get; set; }
public string PropString { get; set; }
public DateTime PropDateTime { get; set; }
public bool PropBool {get; set;}
public static string SerializeAsFormData(object obj)
var keyValuePairList = new List<KeyValuePair<string, string>>();
foreach(PropertyInfo propertyInfo in obj.GetType().GetProperties())
keyValuePairList.Add(new KeyValuePair<string, string>(propertyInfo.Name, HttpUtility.UrlEncode(propertyInfo.GetValue(obj, null).ToString())));
return String.Join('&', keyValuePairList.Select(x => new string(x.Key + "=" + x.Value)));