如何在 HttpRequestMessageExtensions 中添加更多自定义方法 class

How to add more custom methods in HttpRequestMessageExtensions class

return Request.CreateResponse(HttpStatusCode.BadRequest, new mymethodresponse
                {
                    ID= Idval,
                    Created= false
                }

这里是如何为 createresponse 方法创建更多的重载

下面是工作demo,大家可以参考一下

1.Create 一个 HttpRequestMessageExtensions class

public static class HttpRequestMessageExtensions
    {
        public static HttpResponseMessage CreateResponse(this HttpRequestMessage request, HttpStatusCode statusCode, string TestParas)
        {
            return new HttpResponseMessage
            {
                StatusCode = statusCode,
                RequestMessage = request
            };
        }
     }

2.In控制器如下

public class OverloadController : Controller
    {
        public HttpResponseMessage Call(HttpRequestMessage RequestMessage)
        {
            return RequestMessage.CreateResponse();//do your staff...

        }
     
    }

结果: