private void MapArgumentsByPosition(Route source, ParameterInfo[] requiredArguments, NameValueCollection headers, int skipNumberOfDestinationArguments, List <KeyValuePair <Type, ParameterNameAndLocation> > map) { if ((requiredArguments.Length - skipNumberOfDestinationArguments) != source.QueryParameters.Count() + source.RouteParameters.Count()) { throw new InvalidOperationException("Either use parameter names mathing the query and route parameters or specify as many parameters as the combined number of route and query variables"); } IEnumerator headerParameters = headers.AllKeys.GetEnumerator(); IEnumerator <string> routeParameters = source.RouteParameters.GetEnumerator(); IEnumerator <string> queryParameters = source.QueryParameters.GetEnumerator(); foreach (ParameterInfo argument in requiredArguments.Skip(skipNumberOfDestinationArguments)) { if (headerParameters.MoveNext()) { object value = RouteHelpers.GetHeaderParameterValue((string)headerParameters.Current, headers, argument.ParameterType); if (value != null) { map.Add(new KeyValuePair <Type, ParameterNameAndLocation>(argument.ParameterType, new ParameterNameAndLocation { Name = routeParameters.Current, Location = ParameterLocation.Header })); } } if (routeParameters.MoveNext()) { map.Add(new KeyValuePair <Type, ParameterNameAndLocation>(argument.ParameterType, new ParameterNameAndLocation { Name = routeParameters.Current, Location = ParameterLocation.Route })); } else { queryParameters.MoveNext(); map.Add(new KeyValuePair <Type, ParameterNameAndLocation>(argument.ParameterType, new ParameterNameAndLocation { Name = queryParameters.Current, Location = ParameterLocation.Query })); } } }
public object GetHeaderParameterValue(string parameterName, NameValueCollection headers, Type expectedType) { return(RouteHelpers.GetHeaderParameterValue(parameterName, headers, expectedType)); }