I was in the middle of writing a URL helper for the default route in MVC, with this signature:
static string Default(this UrlHelper url, string controller, string action, object id)
My initial implementation looked like this:
static string Default(this UrlHelper url, string controller, string action, object id)
{
return url.RouteUrl("default", new { controller = controller,
action = action,
id = id });
}
That's when Resharper chimed in and grayed some things out for me, teaching me a new trick: If you want your anonymous object field names to be the same as the value you're passing in, you don't need the name.
The abbreviated version looks like this:
static string Default(this UrlHelper url, string controller, string action, object id)
{
return url.RouteUrl("default", new { controller, action, id });
}