The answer in this link is very simple and great:
http://stackoverflow.com/questions/3481923/in-c-sharp-convert-anonymous-type-into-key-value-array
http://stackoverflow.com/questions/3481923/in-c-sharp-convert-anonymous-type-into-key-value-array
var a = new { data1 = "test1", data2 = "sam", data3 = "bob" };
var type = a.GetType();
var props = type.GetProperties();
var pairs = props.Select(x => x.Name + "=" + x.GetValue(a, null)).ToArray();
var result = string.Join("&", pairs);
No comments:
Post a Comment