问题描述
HttpStatusCode
被实现为enum
,每个可能的值都分配给其相应的HTTP状态代码(例如(int)HttpStatusCode.Ok == 200
).
HttpStatusCode
is implemented as an enum
, with each possible value assigned to its corresponding HTTP status code (e.g. (int)HttpStatusCode.Ok == 200
).
但是,HttpMethod
是实现为class
,具有静态属性,可获取各种HTTP动词(HttpStatus.GET
,HttpStatus.PUT
等)的实例. not 将HttpMethod
实现为enum
的背后原理是什么?
However, HttpMethod
is implemented as a class
, with static properties to get instances for the various HTTP verbs (HttpStatus.GET
, HttpStatus.PUT
etc). What is the rationale behind not implementing HttpMethod
as an enum
?
推荐答案
来自(重点是我):
HttpMethod的最常见用法是在此类上使用静态属性之一. 但是,如果应用程序需要不同的HTTP方法值,则HttpMethod构造函数会使用应用程序指定的HTTP方法来初始化HttpMethod的新实例.
The most common usage of HttpMethod is to use one of the static properties on this class. However, if an app needs a different value for the HTTP method, the HttpMethod constructor initializes a new instance of the HttpMethod with an HTTP method that the app specifies.
用枚举当然是不可能的.
Which is of course not possible with an enum.
这篇关于为什么System.Net.Http.HttpMethod是类而不是枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!