Class HttpMethodExtensions
- Namespace
- Cuemon.Extensions.Net.Http
- Assembly
- Cuemon.Extensions.Net.dll
This is an extension implementation of the HttpMethod class.
public static class HttpMethodExtensions
- Inheritance
-
HttpMethodExtensions
Examples
The following example demonstrates how to convert between System.Net.Http.HttpMethod and the Cuemon HttpMethods enum using HttpMethodExtensions.
using System;
using System.Net.Http;
using Cuemon.Extensions.Net.Http;
using Cuemon.Net.Http;
namespace MyApp.Net
{
public class HttpMethodExtensionsExample
{
public void Demonstrate()
{
// Convert System.Net.Http.HttpMethod to the Cuemon HttpMethods enum
HttpMethod getMethod = HttpMethod.Get;
HttpMethods method = getMethod.ToHttpMethod();
Console.WriteLine($"{getMethod} -> {method}"); // GET -> Get
HttpMethod postMethod = HttpMethod.Post;
HttpMethods post = postMethod.ToHttpMethod();
Console.WriteLine($"{postMethod} -> {post}"); // POST -> Post
// Custom HTTP methods are also supported
var patchMethod = new HttpMethod("PATCH");
HttpMethods patch = patchMethod.ToHttpMethod();
Console.WriteLine($"{patchMethod} -> {patch}"); // PATCH -> Patch
// Check flags with bitwise operations
if (method.HasFlag(HttpMethods.Get))
{
Console.WriteLine("This is a GET request.");
}}}
}
Methods
ToHttpMethod(HttpMethod)
Converts the specified method to its equivalent HttpMethods representation.
public static HttpMethods ToHttpMethod(this HttpMethod method)
Parameters
methodHttpMethodThe HttpMethod to be converted.
Returns
- HttpMethods
A HttpMethods representation of the specified
method.
Exceptions
- ArgumentNullException
methodcannot be null.