private List <object> ResolveConstructorParameters(RouteMatch match, TcpClient client, RequestContext context, ConstructorInfo constructor) { List <object> parameters = new List <object>(); ParameterInfo[] constructorParameters = constructor.GetParameters(); foreach (ParameterInfo currentParameter in constructorParameters) { object resolvedParameter = ServiceProvider.GetService(currentParameter.ParameterType); if (resolvedParameter != null) { parameters.Add(resolvedParameter); } else if (currentParameter.ParameterType == typeof(RequestContext)) { parameters.Add(context); } else if (currentParameter.ParameterType == typeof(TcpClient)) { parameters.Add(client); } else if (currentParameter.ParameterType == typeof(NetworkStream)) { parameters.Add(client.GetStream()); } else { NotSupportedException innerException = new NotSupportedException( $"Could not resolve ConstructorParameter:{currentParameter.Name} of Type:{currentParameter.ParameterType}."); EndPointHandlerException error = BuildEndpointHandlerException(match, innerException); throw error; } } return(parameters); }
private static byte[] ExtractFromRequestBody(RouteMatch match, RequestContext context, RequestBodyExtractor bodyExtractor, ParameterInfo actionParameter) { if (supportedContentTypes.Any(sct => sct.Equals(context.Content.ContentType, StringComparison.OrdinalIgnoreCase))) { if (bodyExtractor.BodyExtracted) { return(bodyExtractor.Cache.ToArray()); } else { try { return(bodyExtractor.Extract()); } catch (RequestBodyExtractorException bodyExtractorEx) { EndPointHandlerException error = BuildEndpointHandlerException( $"Could not Resolve Action Parameter:{actionParameter.Name} of Type: {actionParameter.ParameterType}.", match, bodyExtractorEx ); throw error; } } } else { NotSupportedException innerException = new NotSupportedException( $"Could not Resolve Action Parameter:{actionParameter.Name} of Type: {actionParameter.ParameterType}. " + $"Invalid Content-Type:{context.Content.ContentType}. " + $"Supported Contenttypes are: {string.Join(',', supportedContentTypes)}"); throw BuildEndpointHandlerException(match, innerException); } }