Skip to content

Commit b2abda8

Browse files
committed
序列化与反序列化添加 IJsonTypeInfoResolver 使用
1 parent fb276ef commit b2abda8

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

WinGetStore/Helpers/SettingsHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class SystemTextJsonObjectSerializer : IObjectSerializer
7676
string => JsonSerializer.Serialize(value, SourceGenerationContext.Default.String),
7777
ElementTheme => JsonSerializer.Serialize(value, SourceGenerationContext.Default.ElementTheme),
7878
DateTimeOffset => JsonSerializer.Serialize(value, SourceGenerationContext.Default.DateTimeOffset),
79-
_ => default
79+
_ => JsonSerializer.Serialize(value, typeof(T), SourceGenerationContext.Default)
8080
};
8181

8282
public T Deserialize<T>([StringSyntax(StringSyntaxAttribute.Json)] string value)
@@ -87,8 +87,9 @@ public T Deserialize<T>([StringSyntax(StringSyntaxAttribute.Json)] string value)
8787
: type == typeof(string) ? Deserialize(value, SourceGenerationContext.Default.String)
8888
: type == typeof(ElementTheme) ? Deserialize(value, SourceGenerationContext.Default.ElementTheme)
8989
: type == typeof(DateTimeOffset) ? Deserialize(value, SourceGenerationContext.Default.DateTimeOffset)
90-
: default;
91-
static T Deserialize<TValue>([StringSyntax(StringSyntaxAttribute.Json)] string json, JsonTypeInfo<TValue> jsonTypeInfo) => JsonSerializer.Deserialize(json, jsonTypeInfo) is T value ? value : default;
90+
: JsonSerializer.Deserialize(value, typeof(T), SourceGenerationContext.Default) is T result ? result : default;
91+
static T Deserialize<TValue>([StringSyntax(StringSyntaxAttribute.Json)] string json, JsonTypeInfo<TValue> jsonTypeInfo) =>
92+
JsonSerializer.Deserialize(json, jsonTypeInfo) is T value ? value : default;
9293
}
9394
}
9495

WinGetStore/WinGetStore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="CommunityToolkit.Labs.Uwp.Controls.MarkdownTextBlock" Version="0.1.250319-build.2093" />
25+
<PackageReference Include="CommunityToolkit.Labs.Uwp.Controls.MarkdownTextBlock" Version="0.1.250609-build.2144" />
2626
<PackageReference Include="CommunityToolkit.Uwp.Converters" Version="8.2.250402" />
2727
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.2.250402" />
2828
<PackageReference Include="CommunityToolkit.Uwp.Triggers" Version="8.2.250402" />
2929
<PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.6.3" />
30-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.4" />
30+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.5" />
3131
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
3232
<PackageReference Include="Microsoft.UI.Xaml" Version="2.8.7" />
3333
<PackageReference Include="Microsoft.WindowsPackageManager.ComInterop" Version="1.10.340" />

0 commit comments

Comments
 (0)