Saturday
02May2009
Extension method digest #4 RouteBase.AsRoute
Saturday, May 2, 2009 at 1:14PM 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.
Reader Comments