private static EndpointHandlerParameterDeclaration[] BuildEndpointParameterInfo(MethodInfo methodInfo, DeclaredRouteInfo declaredRouteInfo, EndpointDeclarationFactoryOptions options)
        {
            var parameters = methodInfo.GetParameters();

            if (parameters is null)
            {
                return(Array.Empty <EndpointHandlerParameterDeclaration>());
            }
            EndpointHandlerParameterDeclaration[] results = new EndpointHandlerParameterDeclaration[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                results[i] = EndpointParameterInfoFactory.BuildEndpointParameterDeclaration(parameters[i], declaredRouteInfo.Parameters, options);
            }
            return(results);
        }
        public static EndpointRequestHandlerDeclaration BuildFactoryForEndpoint(TypeInfo endpointType, DeclaredRouteInfo routeInfo, EndpointDeclarationFactoryOptions options)
        {
            var handleMethods = endpointType.DeclaredMethods.Where(m => m.IsPublic && (m.Name is "Handle" or "HandleAsync")).ToArray();

            if (handleMethods.Length != 1 || handleMethods[0] is null)
            {
                throw new InvalidEndpointSetupException($"{endpointType.Name} does not contain a single public method named Handle or HandleAsync");
            }

            var handleMethod  = handleMethods[0];
            var parameterInfo = BuildEndpointParameterInfo(handleMethod, routeInfo, options);

            if (handleMethod.ReturnType == typeof(void))
            {
                return(BuildNoContentResponse(new VoidEndpointMethodExecutor(endpointType, handleMethod), parameterInfo));
            }
            if (handleMethod.ReturnType == typeof(Task))
            {
                return(BuildNoContentResponse(new TaskEndpointMethodExecutor(endpointType, handleMethod), parameterInfo));
            }
            if (handleMethod.ReturnType == typeof(ValueTask))
            {
                return(BuildNoContentResponse(new ValueTaskEndpointMethodExecutor(endpointType, handleMethod), parameterInfo));
            }

            var(endpointMethodExecutor, returnType) = GetMethodExcutorAndReturnTypeFor(endpointType, handleMethod);

            if (typeof(IEndpointResult).IsAssignableFrom(returnType))
            {
                return(BuildForEndpointResultResponse(endpointMethodExecutor, parameterInfo));
            }

            if (returnType == typeof(string))
            {
                return(BuildForStringResponse(endpointMethodExecutor, parameterInfo, returnType));
            }

            return(BuildForObjectResponse(endpointMethodExecutor, parameterInfo, returnType));
        }