Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / AreaRegistrationContext.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.Collections.Generic;\r
16     using System.Diagnostics.CodeAnalysis;\r
17     using System.Linq;\r
18     using System.Web.Routing;\r
19 \r
20     public class AreaRegistrationContext {\r
21 \r
22         private readonly HashSet<string> _namespaces = new HashSet<string>(StringComparer.OrdinalIgnoreCase);\r
23 \r
24         public AreaRegistrationContext(string areaName, RouteCollection routes)\r
25             : this(areaName, routes, null) {\r
26         }\r
27 \r
28         public AreaRegistrationContext(string areaName, RouteCollection routes, object state) {\r
29             if (String.IsNullOrEmpty(areaName)) {\r
30                 throw Error.ParameterCannotBeNullOrEmpty("areaName");\r
31             }\r
32             if (routes == null) {\r
33                 throw new ArgumentNullException("routes");\r
34             }\r
35 \r
36             AreaName = areaName;\r
37             Routes = routes;\r
38             State = state;\r
39         }\r
40 \r
41         public string AreaName {\r
42             get;\r
43             private set;\r
44         }\r
45 \r
46         public ICollection<string> Namespaces {\r
47             get {\r
48                 return _namespaces;\r
49             }\r
50         }\r
51 \r
52         public RouteCollection Routes {\r
53             get;\r
54             private set;\r
55         }\r
56 \r
57         public object State {\r
58             get;\r
59             private set;\r
60         }\r
61 \r
62         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",\r
63             Justification = "This is not a regular URL as it may contain special routing characters.")]\r
64         public Route MapRoute(string name, string url) {\r
65             return MapRoute(name, url, (object)null /* defaults */);\r
66         }\r
67 \r
68         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",\r
69             Justification = "This is not a regular URL as it may contain special routing characters.")]\r
70         public Route MapRoute(string name, string url, object defaults) {\r
71             return MapRoute(name, url, defaults, (object)null /* constraints */);\r
72         }\r
73 \r
74         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",\r
75             Justification = "This is not a regular URL as it may contain special routing characters.")]\r
76         public Route MapRoute(string name, string url, object defaults, object constraints) {\r
77             return MapRoute(name, url, defaults, constraints, null /* namespaces */);\r
78         }\r
79 \r
80         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",\r
81             Justification = "This is not a regular URL as it may contain special routing characters.")]\r
82         public Route MapRoute(string name, string url, string[] namespaces) {\r
83             return MapRoute(name, url, (object)null /* defaults */, namespaces);\r
84         }\r
85 \r
86         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",\r
87             Justification = "This is not a regular URL as it may contain special routing characters.")]\r
88         public Route MapRoute(string name, string url, object defaults, string[] namespaces) {\r
89             return MapRoute(name, url, defaults, null /* constraints */, namespaces);\r
90         }\r
91 \r
92         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",\r
93             Justification = "This is not a regular URL as it may contain special routing characters.")]\r
94         public Route MapRoute(string name, string url, object defaults, object constraints, string[] namespaces) {\r
95             if (namespaces == null && Namespaces != null) {\r
96                 namespaces = Namespaces.ToArray();\r
97             }\r
98 \r
99             Route route = Routes.MapRoute(name, url, defaults, constraints, namespaces);\r
100             route.DataTokens["area"] = AreaName;\r
101 \r
102             // disabling the namespace lookup fallback mechanism keeps this areas from accidentally picking up\r
103             // controllers belonging to other areas\r
104             bool useNamespaceFallback = (namespaces == null || namespaces.Length == 0);\r
105             route.DataTokens["UseNamespaceFallback"] = useNamespaceFallback;\r
106 \r
107             return route;\r
108         }\r
109 \r
110     }\r
111 }\r