为什么 System.Net.Http.HttpMethod 是 class,而不是枚举?
Why is System.Net.Http.HttpMethod a class, not an enum?
HttpStatusCode
实现为 enum
,每个可能的值都分配给相应的 HTTP 状态代码(例如 (int)HttpStatusCode.Ok == 200
)。
但是,HttpMethod
是 implemented as a class
,具有静态属性以获取各种 HTTP 动词(HttpMethod.Get
、HttpMethod.Put
等)的实例。 不将HttpMethod
实现为enum
背后的基本原理是什么?
来自 documentation(强调我的):
Remarks
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.
枚举当然不可能。
查看其constructor and method property。
在年之后,我想微软已经听到了你的愿望...
这是你想要的...
HttpStatusCode
实现为 enum
,每个可能的值都分配给相应的 HTTP 状态代码(例如 (int)HttpStatusCode.Ok == 200
)。
但是,HttpMethod
是 implemented as a class
,具有静态属性以获取各种 HTTP 动词(HttpMethod.Get
、HttpMethod.Put
等)的实例。 不将HttpMethod
实现为enum
背后的基本原理是什么?
来自 documentation(强调我的):
Remarks
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.
枚举当然不可能。
查看其constructor and method property。
在年之后,我想微软已经听到了你的愿望...
这是你想要的...