csharp Flurl Monkey Patching by Namespace Trick
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Flurl Monkey Patching by Namespace Trick相关的知识,希望对你有一定的参考价值。
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Flurl.Http;
namespace FlurlExtensions
{
public static class CustomHttpResponseMessageExtensions
{
//
// Summary:
// Returns HTTP response body as a byte array. Intended to chain off an async call.
//
// Returns:
// A Task whose result is the response body as a byte array.
public static Task<byte []> ReceiveBytes (this Task<HttpResponseMessage> response)
{
return HttpResponseMessageExtensions.ReceiveBytes (response);
}
//
// Summary:
// Deserializes JSON-formatted HTTP response body to a dynamic object. Intended
// to chain off an async call.
//
// Returns:
// A Task whose result is a dynamic object containing data in the response body.
//
// Exceptions:
// T:Flurl.Http.FlurlHttpException:
// Condition.
public static Task<dynamic> ReceiveJson (this Task<HttpResponseMessage> response)
{
return HttpResponseMessageExtensions.ReceiveJson (response);
}
//
// Summary:
// Deserializes JSON-formatted HTTP response body to object of type T. Intended
// to chain off an async HTTP.
//
// Type parameters:
// T:
// A type whose structure matches the expected JSON response.
//
// Returns:
// A Task whose result is an object containing data in the response body.
//
// Exceptions:
// T:Flurl.Http.FlurlHttpException:
// Condition.
public static Task<T> ReceiveJson<T> (this Task<HttpResponseMessage> response)
{
return HttpResponseMessageExtensions.ReceiveJson<T> (response);
}
//
// Summary:
// Deserializes JSON-formatted HTTP response body to a list of dynamic objects.
// Intended to chain off an async call.
//
// Returns:
// A Task whose result is a list of dynamic objects containing data in the response
// body.
//
// Exceptions:
// T:Flurl.Http.FlurlHttpException:
// Condition.
public static Task<IList<dynamic>> ReceiveJsonList (this Task<HttpResponseMessage> response)
{
return HttpResponseMessageExtensions.ReceiveJsonList (response);
}
//
// Summary:
// Returns HTTP response body as a stream. Intended to chain off an async call.
//
// Returns:
// A Task whose result is the response body as a stream.
public static Task<Stream> ReceiveStream (this Task<HttpResponseMessage> response)
{
return HttpResponseMessageExtensions.ReceiveStream (response);
}
//
// Summary:
// Returns HTTP response body as a string. Intended to chain off an async call.
//
// Returns:
// A Task whose result is the response body as a string.
public static Task<string> ReceiveString (this Task<HttpResponseMessage> response)
{
return HttpResponseMessageExtensions.ReceiveString (response);
}
}
}
以上是关于csharp Flurl Monkey Patching by Namespace Trick的主要内容,如果未能解决你的问题,请参考以下文章
typescript Monkey Patch Observable +错误抛出
Python中monkey.patch_all()解决协程阻塞问题
python用from gevent import monkey; monkey.patch_all()之后报ssl等错误