Skip to content

Commit

Permalink
Supports .NET Standard 2.0+ / .NET Framework 4.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xin9le committed Feb 22, 2021
1 parent 47d2c06 commit 58e8af8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/Paidy/Internals/HttpClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ namespace Paidy.Internals
/// </summary>
internal static class HttpClientExtensions
{
#if NETSTANDARD2_0 || NET461
private static readonly HttpMethod PatchMethod = new HttpMethod("PATCH");


/// <summary>
/// Sends a PATCH request with a cancellation token to a Uri represented as a string as an asynchronous operation.
/// </summary>
/// <param name="client"></param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="content">The HTTP request content sent to the server.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
public static Task<HttpResponseMessage> PatchAsync(this HttpClient client, string? requestUri, HttpContent content, CancellationToken cancellationToken = default)
{
var request = new HttpRequestMessage(PatchMethod, requestUri) { Content = content };
return client.SendAsync(request, cancellationToken);
}
#endif


/// <summary>
/// Send the specified instance as JSON via POST method.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Paidy/Internals/HttpContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class HttpContentExtensions
/// <returns></returns>
public static async ValueTask<T> ReadFromJsonAsync<T>(this HttpContent content, IJsonFormatterResolver? resolver = default, CancellationToken cancellationToken = default)
{
#if NETSTANDARD
#if NETSTANDARD || NET461
var payload = await content.ReadAsByteArrayAsync().ConfigureAwait(false);
#else
var payload = await content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Paidy/Internals/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETSTANDARD
#if NETSTANDARD || NET461
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

Expand Down
14 changes: 13 additions & 1 deletion src/Paidy/Paidy.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<!-- NuGet -->
Expand All @@ -28,5 +28,17 @@
<ItemGroup Condition="'$(TargetFramework)' == 'net5'">
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0" />
</ItemGroup>

</Project>

0 comments on commit 58e8af8

Please sign in to comment.