I have an ActionDescriptor
from which I retrieve information about an action and its controller:
ActionDescriptor desc = ...;
string action = desc.ActionName;
string controller = desc.ControllerDescriptor.ControllerName;
string area = ?;
I'm wondering if there is a better way to determine the controller's area than having to parse its namespace, which I'm currently doing like so:
// e.g., Company.Areas.Foo.Controllers
var parts = desc.ControllerDescriptor.ControllerType.Namespace.Split('.').ToList();
var areaIndex = parts.IndexOf("Areas");
if (areaIndex > -1) area = parts[areaIndex + 1];
// area = "Foo"
EDIT:
I should clarify that I'm not in the context of a view or controller and am trying to determine the area only given its Type
information and such.