What’s Wrong With This Code (#25)
The goal: create an extension method that will make it easy to create FormCollection objects. The method is a helper for unit testing ASP.NET MVC code. public static FormCollection ToFormCollection(this object data)
{
var namesAndValues =
data.GetType()
.GetProperties()
.WhereValueIsNotDefaultValue(data)
.ToNameValueCollection(data);
return new FormCollection(namesAndValues);
}
The extension method itself relies on a couple private extension...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.