1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Diagnostics . CodeAnalysis ;
4
5
using System . Text . Json ;
5
6
using System . Text . Json . Serialization ;
6
7
using System . Text . Json . Serialization . Metadata ;
7
8
using System . Threading ;
8
9
using System . Threading . Tasks ;
9
10
11
+ [ assembly: UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2026:RequiresUnreferencedCode" ,
12
+ Target = "M:System.Net.Http.Json.HttpClientJsonExtensions.<GetFromJsonAsyncCore>d__12.MoveNext()" ,
13
+ Scope = "member" ,
14
+ Justification = "Workaround for https://github.com/mono/linker/issues/1416. The outer method is marked as RequiresUnreferencedCode." ) ]
15
+ [ assembly: UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2077:UnrecognizedReflectionPattern" ,
16
+ Target = "M:System.Net.Http.Json.HttpClientJsonExtensions.<GetFromJsonAsyncCore>d__12.MoveNext()" ,
17
+ Scope = "member" ,
18
+ Justification = "Workaround for https://github.com/mono/linker/issues/1416. The outer method is marked as RequiresUnreferencedCode." ) ]
19
+ [ assembly: UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2026:RequiresUnreferencedCode" ,
20
+ Target = "M:System.Net.Http.Json.HttpClientJsonExtensions.<GetFromJsonAsyncCore>d__13`1.MoveNext()" ,
21
+ Scope = "member" ,
22
+ Justification = "Workaround for https://github.com/mono/linker/issues/1416. The outer method is marked as RequiresUnreferencedCode." ) ]
23
+ [ assembly: UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2091:UnrecognizedReflectionPattern" ,
24
+ Target = "M:System.Net.Http.Json.HttpClientJsonExtensions.<GetFromJsonAsyncCore>d__13`1.MoveNext()" ,
25
+ Scope = "member" ,
26
+ Justification = "Workaround for https://github.com/mono/linker/issues/1416. The outer method is marked as RequiresUnreferencedCode." ) ]
27
+
10
28
namespace System . Net . Http . Json
11
29
{
12
30
/// <summary>
13
31
/// Contains the extensions methods for using JSON as the content-type in HttpClient.
14
32
/// </summary>
15
33
public static partial class HttpClientJsonExtensions
16
34
{
17
- public static Task < object ? > GetFromJsonAsync ( this HttpClient client , string ? requestUri , Type type , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
35
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
36
+ public static Task < object ? > GetFromJsonAsync ( this HttpClient client , string ? requestUri , [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] Type type , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
18
37
{
19
38
if ( client == null )
20
39
{
@@ -25,7 +44,8 @@ public static partial class HttpClientJsonExtensions
25
44
return GetFromJsonAsyncCore ( taskResponse , type , options , cancellationToken ) ;
26
45
}
27
46
28
- public static Task < object ? > GetFromJsonAsync ( this HttpClient client , Uri ? requestUri , Type type , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
47
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
48
+ public static Task < object ? > GetFromJsonAsync ( this HttpClient client , Uri ? requestUri , [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] Type type , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
29
49
{
30
50
if ( client == null )
31
51
{
@@ -36,7 +56,8 @@ public static partial class HttpClientJsonExtensions
36
56
return GetFromJsonAsyncCore ( taskResponse , type , options , cancellationToken ) ;
37
57
}
38
58
39
- public static Task < TValue ? > GetFromJsonAsync < TValue > ( this HttpClient client , string ? requestUri , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
59
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
60
+ public static Task < TValue ? > GetFromJsonAsync < [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] TValue > ( this HttpClient client , string ? requestUri , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
40
61
{
41
62
if ( client == null )
42
63
{
@@ -47,7 +68,8 @@ public static partial class HttpClientJsonExtensions
47
68
return GetFromJsonAsyncCore < TValue > ( taskResponse , options , cancellationToken ) ;
48
69
}
49
70
50
- public static Task < TValue ? > GetFromJsonAsync < TValue > ( this HttpClient client , Uri ? requestUri , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
71
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
72
+ public static Task < TValue ? > GetFromJsonAsync < [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] TValue > ( this HttpClient client , Uri ? requestUri , JsonSerializerOptions ? options , CancellationToken cancellationToken = default )
51
73
{
52
74
if ( client == null )
53
75
{
@@ -102,19 +124,24 @@ public static partial class HttpClientJsonExtensions
102
124
return GetFromJsonAsyncCore < TValue > ( taskResponse , jsonTypeInfo , cancellationToken ) ;
103
125
}
104
126
105
- public static Task < object ? > GetFromJsonAsync ( this HttpClient client , string ? requestUri , Type type , CancellationToken cancellationToken = default )
127
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
128
+ public static Task < object ? > GetFromJsonAsync ( this HttpClient client , string ? requestUri , [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] Type type , CancellationToken cancellationToken = default )
106
129
=> client . GetFromJsonAsync ( requestUri , type , options : null , cancellationToken ) ;
107
130
108
- public static Task < object ? > GetFromJsonAsync ( this HttpClient client , Uri ? requestUri , Type type , CancellationToken cancellationToken = default )
131
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
132
+ public static Task < object ? > GetFromJsonAsync ( this HttpClient client , Uri ? requestUri , [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] Type type , CancellationToken cancellationToken = default )
109
133
=> client . GetFromJsonAsync ( requestUri , type , options : null , cancellationToken ) ;
110
134
111
- public static Task < TValue ? > GetFromJsonAsync < TValue > ( this HttpClient client , string ? requestUri , CancellationToken cancellationToken = default )
135
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
136
+ public static Task < TValue ? > GetFromJsonAsync < [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] TValue > ( this HttpClient client , string ? requestUri , CancellationToken cancellationToken = default )
112
137
=> client . GetFromJsonAsync < TValue > ( requestUri , options : null , cancellationToken ) ;
113
138
114
- public static Task < TValue ? > GetFromJsonAsync < TValue > ( this HttpClient client , Uri ? requestUri , CancellationToken cancellationToken = default )
139
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
140
+ public static Task < TValue ? > GetFromJsonAsync < [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] TValue > ( this HttpClient client , Uri ? requestUri , CancellationToken cancellationToken = default )
115
141
=> client . GetFromJsonAsync < TValue > ( requestUri , options : null , cancellationToken ) ;
116
142
117
- private static async Task < object ? > GetFromJsonAsyncCore ( Task < HttpResponseMessage > taskResponse , Type type , JsonSerializerOptions ? options , CancellationToken cancellationToken )
143
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
144
+ private static async Task < object ? > GetFromJsonAsyncCore ( Task < HttpResponseMessage > taskResponse , [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] Type type , JsonSerializerOptions ? options , CancellationToken cancellationToken )
118
145
{
119
146
using ( HttpResponseMessage response = await taskResponse . ConfigureAwait ( false ) )
120
147
{
@@ -126,7 +153,8 @@ public static partial class HttpClientJsonExtensions
126
153
}
127
154
}
128
155
129
- private static async Task < T ? > GetFromJsonAsyncCore < T > ( Task < HttpResponseMessage > taskResponse , JsonSerializerOptions ? options , CancellationToken cancellationToken )
156
+ [ RequiresUnreferencedCode ( HttpContentJsonExtensions . SerializationUnreferencedCodeMessage ) ]
157
+ private static async Task < T ? > GetFromJsonAsyncCore < [ DynamicallyAccessedMembers ( JsonHelpers . DeserializationMemberTypes ) ] T > ( Task < HttpResponseMessage > taskResponse , JsonSerializerOptions ? options , CancellationToken cancellationToken )
130
158
{
131
159
using ( HttpResponseMessage response = await taskResponse . ConfigureAwait ( false ) )
132
160
{
0 commit comments