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)
1414 . AddWebApiClient ( )
1515 . ConfigureHttpApi ( options => // json SG生成器配置
1616 {
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 ) ;
2118 } ) ;
2219
2320 services . AddHttpApi < ICloudflareApi > ( ) ;
Original file line number Diff line number Diff line change @@ -103,5 +103,18 @@ private static JsonSerializerOptions CreateJsonDeserializeOptions()
103103 options . Converters . Add ( JsonCompatibleConverter . DateTimeReader ) ;
104104 return options ;
105105 }
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
106119 }
107120}
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <Nullable >enable</Nullable >
5- <TargetFrameworks >netstandard2.1;net5.0</TargetFrameworks >
5+ <TargetFrameworks >netstandard2.1;net5.0;net8.0 </TargetFrameworks >
66
77 <RootNamespace >WebApiClientCore</RootNamespace >
88 <AssemblyName >WebApiClientCore.Abstractions</AssemblyName >
You can’t perform that action at this time.
0 commit comments