Skip to content

Commit

Permalink
声明对HttpContent的NonPublicProperties依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Jun 21, 2024
1 parent 0b3513a commit 7f451f3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions WebApiClientCore/System.Net.Http/HttpContentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
Expand All @@ -24,7 +25,8 @@ public static class HttpContentExtensions

/// <summary>
/// 静态构造器
/// </summary>
/// </summary>
[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicProperties, typeof(HttpContent))]
static HttpContentExtensions()
{
var property = typeof(HttpContent).GetProperty(IsBufferedPropertyName, BindingFlags.Instance | BindingFlags.NonPublic);
Expand Down Expand Up @@ -70,8 +72,8 @@ public static void EnsureNotBuffered(this HttpContent httpContent)
{
throw new HttpContentBufferedException();
}
}
}

/// <summary>
/// 读取为二进制数组并转换为 utf8 编码
/// </summary>
Expand Down Expand Up @@ -133,7 +135,7 @@ public static Encoding GetEncoding(this HttpContent httpContent)
return encoding.Equals(Encoding.UTF8.WebName, StringComparison.OrdinalIgnoreCase)
? Encoding.UTF8
: Encoding.GetEncoding(encoding.ToString());
}
}

}
}

0 comments on commit 7f451f3

Please sign in to comment.