public static RouteAreaAttribute GetAreaFrom(this ControllerDescriptor controllerDescriptor) { RouteAreaAttribute areaAttribute = controllerDescriptor.GetCustomAttributes(typeof(RouteAreaAttribute), inherit: true) .Cast <RouteAreaAttribute>() .FirstOrDefault(); return(areaAttribute); }
public static string GetPrefixFrom(this ControllerDescriptor controllerDescriptor) { // this only happens once per controller type, for the lifetime of the application, // so we do not need to cache the results object[] routePrefixAttributes = controllerDescriptor.GetCustomAttributes(typeof(RoutePrefixAttribute), inherit: false); if (routePrefixAttributes.Length > 0) { RoutePrefixAttribute routePrefixAttribute = routePrefixAttributes[0] as RoutePrefixAttribute; if (routePrefixAttribute != null) { return(routePrefixAttribute.Prefix); } } return(null); }
private static object GetControllerModel(ControllerDescriptor controllerDescriptor, RequestContext requestContext) { return new { ControllerName = controllerDescriptor.ControllerName, ControllerType = new { Name = controllerDescriptor.ControllerType.Name, Namespace = controllerDescriptor.ControllerType.Namespace, Attributes = GetAttributesModel(controllerDescriptor.GetCustomAttributes(inherit: true)) }, Actions = from action in controllerDescriptor.GetCanonicalActions() let reflectedAction = action as ReflectedActionDescriptor select new { Name = action.ActionName, Id = GetActionId(action), Verbs = GetVerbs(action), Path = GetSamplePath(requestContext, action), MethodInfo = (reflectedAction != null ? reflectedAction.MethodInfo : null), ReturnType = (reflectedAction != null ? reflectedAction.MethodInfo.ReturnType : null), Parameters = from parameter in action.GetParameters() select new { Name = parameter.ParameterName, Type = parameter.ParameterType, IsComplexType = IsComplexType(parameter.ParameterType), DefaultValue = parameter.DefaultValue ?? "" }, Attributes = GetAttributesModel(action.GetCustomAttributes(inherit: true)) }, InputModels = GetInputModels(controllerDescriptor), GlobalFilters = from filter in GlobalFilters.Filters let filterInstance = filter.Instance let filterType = filterInstance.GetType() select new { Name = filterType.Name, Namespace = filterType.Namespace, Properties = from property in filterType.GetProperties() select new { Name = property.Name, Value = property.GetValue(filterInstance, null) } } }; }
public static IEnumerable <IRouteInfoProvider> GetDirectRoutes(this ControllerDescriptor controller) { return(controller.GetCustomAttributes(inherit: false).OfType <IRouteInfoProvider>()); }