Why is System.Net.Http.HttpMethod a class, not an enum?

▼魔方 西西 提交于 2019-12-08 14:37:55

问题


HttpStatusCode is implemented as an enum, with each possible value assigned to its corresponding HTTP status code (e.g. (int)HttpStatusCode.Ok == 200).

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?


回答1:


From the documentation (emphasis mine):

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.

Which is of course not possible with an enum.

See its constructor and method property.



来源:https://stackoverflow.com/questions/39717516/why-is-system-net-http-httpmethod-a-class-not-an-enum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!