File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed
WebApiClientCore.Abstractions Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ static void Main(string[] args)
14
14
. AddWebApiClient ( )
15
15
. ConfigureHttpApi ( options => // json SG生成器配置
16
16
{
17
- var jsonContext = AppJsonSerializerContext . Default ;
18
- options . JsonSerializeOptions . TypeInfoResolverChain . Insert ( 0 , jsonContext ) ;
19
- options . JsonDeserializeOptions . TypeInfoResolverChain . Insert ( 0 , jsonContext ) ;
20
- options . KeyValueSerializeOptions . GetJsonSerializerOptions ( ) . TypeInfoResolverChain . Insert ( 0 , jsonContext ) ;
17
+ options . PrependJsonSerializerContext ( AppJsonSerializerContext . Default ) ;
21
18
} ) ;
22
19
23
20
services . AddHttpApi < ICloudflareApi > ( ) ;
Original file line number Diff line number Diff line change @@ -103,5 +103,18 @@ private static JsonSerializerOptions CreateJsonDeserializeOptions()
103
103
options . Converters . Add ( JsonCompatibleConverter . DateTimeReader ) ;
104
104
return options ;
105
105
}
106
+
107
+ #if NET8_0_OR_GREATER
108
+ /// <summary>
109
+ /// 插入指定的<see cref="System.Text.Json.Serialization.JsonSerializerContext"/>到所有序列化选项的TypeInfoResolverChain的最前位置
110
+ /// </summary>
111
+ /// <param name="context"></param>
112
+ public void PrependJsonSerializerContext ( System . Text . Json . Serialization . JsonSerializerContext context )
113
+ {
114
+ this . JsonSerializeOptions . TypeInfoResolverChain . Insert ( 0 , context ) ;
115
+ this . JsonDeserializeOptions . TypeInfoResolverChain . Insert ( 0 , context ) ;
116
+ this . KeyValueSerializeOptions . GetJsonSerializerOptions ( ) . TypeInfoResolverChain . Insert ( 0 , context ) ;
117
+ }
118
+ #endif
106
119
}
107
120
}
Original file line number Diff line number Diff line change 2
2
3
3
<PropertyGroup >
4
4
<Nullable >enable</Nullable >
5
- <TargetFrameworks >netstandard2.1;net5.0</TargetFrameworks >
5
+ <TargetFrameworks >netstandard2.1;net5.0;net8.0 </TargetFrameworks >
6
6
7
7
<RootNamespace >WebApiClientCore</RootNamespace >
8
8
<AssemblyName >WebApiClientCore.Abstractions</AssemblyName >
You can’t perform that action at this time.
0 commit comments