Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / AreaRegistration.cs
1 namespace System.Web.Mvc {
2     using System;
3     using System.Collections.Generic;
4     using System.Web.Routing;
5
6     public abstract class AreaRegistration {
7
8         private const string _typeCacheName = "MVC-AreaRegistrationTypeCache.xml";
9
10         public abstract string AreaName {
11             get;
12         }
13
14         internal void CreateContextAndRegister(RouteCollection routes, object state) {
15             AreaRegistrationContext context = new AreaRegistrationContext(AreaName, routes, state);
16
17             string thisNamespace = GetType().Namespace;
18             if (thisNamespace != null) {
19                 context.Namespaces.Add(thisNamespace + ".*");
20             }
21
22             RegisterArea(context);
23         }
24
25         private static bool IsAreaRegistrationType(Type type) {
26             return
27                 typeof(AreaRegistration).IsAssignableFrom(type) &&
28                 type.GetConstructor(Type.EmptyTypes) != null;
29         }
30
31         public static void RegisterAllAreas() {
32             RegisterAllAreas(null);
33         }
34
35         public static void RegisterAllAreas(object state) {
36             RegisterAllAreas(RouteTable.Routes, new BuildManagerWrapper(), state);
37         }
38
39         internal static void RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, object state) {
40             List<Type> areaRegistrationTypes = TypeCacheUtil.GetFilteredTypesFromAssemblies(_typeCacheName, IsAreaRegistrationType, buildManager);
41             foreach (Type areaRegistrationType in areaRegistrationTypes) {
42                 AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(areaRegistrationType);
43                 registration.CreateContextAndRegister(routes, state);
44             }
45         }
46
47         public abstract void RegisterArea(AreaRegistrationContext context);
48
49     }
50 }