/// <summary> /// Returns a Route Handler for the given request. /// </summary> /// <param name="request"></param> /// <returns></returns> internal static RouteHandler GetRouteHandler(GuardianRequest request) { RouteConfiguration matchingRouteConfiguration = GetConfiguredRoute(request); if (matchingRouteConfiguration == null) { return(null); } // Does the target method have an expected parameter? (Only one is allowed currently) Type parameterType = matchingRouteConfiguration.ControllerMethodInfo.GetParameters() .Select(mi => mi.ParameterType) .SingleOrDefault(); if (parameterType == null) { return(new RouteHandler(matchingRouteConfiguration.ControllerMethodInfo)); } return(new RouteHandler(matchingRouteConfiguration.ControllerMethodInfo, GetRequestParameters(request, parameterType, matchingRouteConfiguration))); }
/// <summary> /// Returns non-null parameters foudn in given request. /// </summary> /// <param name="request"></param> /// <param name="parameterType"></param> /// <param name="routeConfiguration"></param> /// <returns></returns> private static object[] GetRequestParameters(GuardianRequest request, Type parameterType, RouteConfiguration routeConfiguration) { List <object> potentialParameters = new List <object>(); potentialParameters.Add(GetDeserializedStream(request.Body, parameterType)); potentialParameters.Add(GetTypedRouteParameter(request.Path, routeConfiguration.Path, parameterType)); return(potentialParameters .Where(p => p != null) .ToArray()); }