Can be used to serialize an object to a QueryString.
public static class HtmlHelper
{
public static string SerializeToQueryString(object source)
{
if (source == null)
throw new ArgumentNullException("source");
return String.Join(
"&",
source.GetType().GetProperties()
.Select(p => new { Name = p.Name, Value = p.GetValue(source, new object[] {}) })
.Where(p => p.Value != null)
.Select(p => String.Format("{0}={1}", p.Name, p.Value))
.ToArray()
);
}
}
Fork
Fork of Serialize an object into a Querystring, using LINQ syntax - @benlaan Thursday 17, 2011 6:03 AM
1 Feedback
You must log in before you can give any feedback
You must log in before you can post a comment


1.07k
0




Mark 'asp.net' tag as 'like'
Mark 'asp.net' tag as 'ignore'