New tests.
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / AreaHelpers.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Web.Routing;\r
16 \r
17     internal static class AreaHelpers {\r
18 \r
19         public static string GetAreaName(RouteBase route) {\r
20             IRouteWithArea routeWithArea = route as IRouteWithArea;\r
21             if (routeWithArea != null) {\r
22                 return routeWithArea.Area;\r
23             }\r
24 \r
25             Route castRoute = route as Route;\r
26             if (castRoute != null && castRoute.DataTokens != null) {\r
27                 return castRoute.DataTokens["area"] as string;\r
28             }\r
29 \r
30             return null;\r
31         }\r
32 \r
33         public static string GetAreaName(RouteData routeData) {\r
34             object area;\r
35             if (routeData.DataTokens.TryGetValue("area", out area)) {\r
36                 return area as string;\r
37             }\r
38 \r
39             return GetAreaName(routeData.Route);\r
40         }\r
41 \r
42     }\r
43 }\r