Class HttpContentExtensions
Extensions for the HttpContent
Inheritance
Inherited Members
Namespace: Dapplo.HttpExtensions
Assembly: Dapplo.HttpExtensions.dll
Syntax
public static class HttpContentExtensions
Methods
| Improve this Doc View SourceGetAsAsync(HttpContent, Type, HttpStatusCode, CancellationToken)
Extension method reading the httpContent to a Typed object, depending on the returned content-type Currently we support: Json objects which are annotated with the DataContract/DataMember attributes
Declaration
public static async Task<object> GetAsAsync(this HttpContent httpContent, Type resultType, HttpStatusCode httpStatusCode, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | httpContent | HttpContent |
| Type | resultType | The Type to read into |
| HttpStatusCode | httpStatusCode | HttpStatusCode |
| CancellationToken | cancellationToken | CancellationToken |
Returns
| Type | Description |
|---|---|
| Task<System.Object> | the deserialized object of type T |
GetAsAsync<TResult>(HttpContent, HttpStatusCode, CancellationToken)
Extension method reading the httpContent to a Typed object, depending on the returned content-type Currently we support: Json objects which are annotated with the DataContract/DataMember attributes
Declaration
public static async Task<TResult> GetAsAsync<TResult>(this HttpContent httpContent, HttpStatusCode httpStatusCode, CancellationToken cancellationToken = null)
where TResult : class
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | httpContent | HttpContent |
| HttpStatusCode | httpStatusCode | HttpStatusCode |
| CancellationToken | cancellationToken | CancellationToken |
Returns
| Type | Description |
|---|---|
| Task<TResult> | the deserialized object of type T |
Type Parameters
| Name | Description |
|---|---|
| TResult | The Type to read into |
GetContentStream(HttpContent)
Get the Content-stream of the HttpContent, wrap it in ProgressStream if this is specified
Declaration
public static async Task<Stream> GetContentStream(this HttpContent httpContent)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | httpContent |
Returns
| Type | Description |
|---|---|
| Task<System.IO.Stream> | Stream from ReadAsStreamAsync eventually wrapped by ProgressStream |
GetContentType(HttpContent)
Simply return the content type of the HttpContent
Declaration
public static string GetContentType(this HttpContent httpContent)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | httpContent | HttpContent |
Returns
| Type | Description |
|---|---|
| System.String | string with the content type |
SetContentType(HttpContent, String)
Simply set the content type of the HttpContent
Declaration
public static void SetContentType(this HttpContent httpContent, string contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | httpContent | HttpContent |
| System.String | contentType | Content-Type to set |