Navigation
About Me

MS certified C#/ASP.NET software developer from Baltimore, MD.

Search
Subscribe
« Where has all the content gone? | Main | Optimizing URL generation in ASP.NET MVC – Part 2 »
Saturday
02May2009

Extension method digest #4 RouteBase.AsRoute

This one is very simple but is extremely helpful when dabbling in the System.Web.Routing namespace.  Using AsRoute extension will allow you to get to the properties and methods on the Route type itself like Constraints, Defaults and Url.

public static class RouteBaseExtensions
{
public static Route AsRoute(this RouteBase routeBase)
{
return routeBase as Route;
}
}

Again, a very simple extension method that can help save some time instead of having to cast the object yourself.  If the RouteBase target isn’t a Route itself it will just return null.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>