1 namespace System.Web.Mvc {
3 using System.Collections.Generic;
4 using System.Web.Routing;
6 public abstract class AreaRegistration {
8 private const string _typeCacheName = "MVC-AreaRegistrationTypeCache.xml";
10 public abstract string AreaName {
14 internal void CreateContextAndRegister(RouteCollection routes, object state) {
15 AreaRegistrationContext context = new AreaRegistrationContext(AreaName, routes, state);
17 string thisNamespace = GetType().Namespace;
18 if (thisNamespace != null) {
19 context.Namespaces.Add(thisNamespace + ".*");
22 RegisterArea(context);
25 private static bool IsAreaRegistrationType(Type type) {
27 typeof(AreaRegistration).IsAssignableFrom(type) &&
28 type.GetConstructor(Type.EmptyTypes) != null;
31 public static void RegisterAllAreas() {
32 RegisterAllAreas(null);
35 public static void RegisterAllAreas(object state) {
36 RegisterAllAreas(RouteTable.Routes, new BuildManagerWrapper(), state);
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);
47 public abstract void RegisterArea(AreaRegistrationContext context);