예제 #1
0
 /// <summary>
 /// Find a type that will be the controller for the given content item.
 /// </summary>
 /// <param name="item">A content item which needs a controller.</param>
 /// <returns>The type of the controller that will control the content item or null if there is none</returns>
 public Type FindControllerFor(ContentItem item)
 {
     Type itemType = item.GetType();
     while (itemType.BaseType != typeof(Object)) {
         // The convention is that controllers will be named [ContentItemTypeName]Controller
         string controllerName = itemType.Name + "Controller";
         var matchingContollerType = assemblies
             .SelectMany(t=>t.GetTypes())
             .Where(t=>t.Name==controllerName && typeof(IController).IsAssignableFrom(t)).SingleOrDefault();
         // TODO: Consider a new algorithm that searches for types that derive from ContentController<>, matching on the generic type parameter
         if ( matchingContollerType != null ) {
             return matchingContollerType;
         }
         itemType = itemType.BaseType;
     }
     return null;
 }
 public static void SetContentItem(this RouteValueDictionary dict, ContentItem item)
 {
     dict["content-item"] = item;
 }
예제 #3
0
 /// <summary>
 /// Find the standard name of a controller for the given content item.
 /// </summary>
 /// <param name="item">A content item which needs a controller.</param>
 /// <returns>The name of the controller that will control the content item or null if there is none</returns>
 /// <remarks>
 /// Note that this name will be the MVC standard name in the sense that the actual type name will be have Controller on the end.
 /// For example if the name is Page, the actual class will be PageController.
 /// </remarks>
 public string FindControllerNameFor(ContentItem item)
 {
     Type controllerType = FindControllerFor(item);
     return GetControllerName(controllerType);
 }