Skip to content

Commit

Permalink
优化 JSON 序列化排版
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Aug 30, 2024
1 parent f3372b6 commit 67ca4a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
45 changes: 23 additions & 22 deletions CoreAppUWP/Controls/SettingsCard/SettingsCard.ThemeResources.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contract13Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,13)"
xmlns:contract14NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,14)"
xmlns:contract14Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,14)"
xmlns:controls="using:CoreAppUWP.Controls"
Expand Down Expand Up @@ -447,23 +448,30 @@
x:Name="Root"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
CheckBoxBorderBrush="{ThemeResource ListViewItemCheckBoxBorderBrush}"
contract13Present:CheckBoxBorderBrush="{ThemeResource ListViewItemCheckBoxBorderBrush}"
contract13Present:CheckBoxCornerRadius="{ThemeResource ListViewItemCheckBoxCornerRadius}"
contract13Present:CheckBoxDisabledBorderBrush="{ThemeResource ListViewItemCheckBoxDisabledBorderBrush}"
contract13Present:CheckBoxDisabledBrush="{ThemeResource ListViewItemCheckBoxDisabledBrush}"
contract13Present:CheckBoxPointerOverBorderBrush="{ThemeResource ListViewItemCheckBoxPointerOverBorderBrush}"
contract13Present:CheckBoxPointerOverBrush="{ThemeResource ListViewItemCheckBoxPointerOverBrush}"
contract13Present:CheckBoxPressedBorderBrush="{ThemeResource ListViewItemCheckBoxPressedBorderBrush}"
contract13Present:CheckBoxPressedBrush="{ThemeResource ListViewItemCheckBoxPressedBrush}"
contract13Present:CheckBoxSelectedBrush="{ThemeResource ListViewItemCheckBoxSelectedBrush}"
contract13Present:CheckBoxSelectedDisabledBrush="{ThemeResource ListViewItemCheckBoxSelectedDisabledBrush}"
contract13Present:CheckBoxSelectedPointerOverBrush="{ThemeResource ListViewItemCheckBoxSelectedPointerOverBrush}"
contract13Present:CheckBoxSelectedPressedBrush="{ThemeResource ListViewItemCheckBoxSelectedPressedBrush}"
contract13Present:CheckDisabledBrush="{ThemeResource ListViewItemCheckDisabledBrush}"
contract13Present:CheckPressedBrush="{ThemeResource ListViewItemCheckPressedBrush}"
contract13Present:SelectedDisabledBackground="{ThemeResource ListViewItemBackgroundSelectedDisabled}"
contract13Present:SelectionIndicatorBrush="{ThemeResource ListViewItemSelectionIndicatorBrush}"
contract13Present:SelectionIndicatorCornerRadius="{ThemeResource ListViewItemSelectionIndicatorCornerRadius}"
contract13Present:SelectionIndicatorDisabledBrush="{ThemeResource ListViewItemSelectionIndicatorDisabledBrush}"
contract13Present:SelectionIndicatorPointerOverBrush="{ThemeResource ListViewItemSelectionIndicatorPointerOverBrush}"
contract13Present:SelectionIndicatorPressedBrush="{ThemeResource ListViewItemSelectionIndicatorPressedBrush}"
contract13Present:SelectionIndicatorVisualEnabled="{ThemeResource ListViewItemSelectionIndicatorVisualEnabled}"
CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}"
CheckBoxCornerRadius="{ThemeResource ListViewItemCheckBoxCornerRadius}"
CheckBoxDisabledBorderBrush="{ThemeResource ListViewItemCheckBoxDisabledBorderBrush}"
CheckBoxDisabledBrush="{ThemeResource ListViewItemCheckBoxDisabledBrush}"
CheckBoxPointerOverBorderBrush="{ThemeResource ListViewItemCheckBoxPointerOverBorderBrush}"
CheckBoxPointerOverBrush="{ThemeResource ListViewItemCheckBoxPointerOverBrush}"
CheckBoxPressedBorderBrush="{ThemeResource ListViewItemCheckBoxPressedBorderBrush}"
CheckBoxPressedBrush="{ThemeResource ListViewItemCheckBoxPressedBrush}"
CheckBoxSelectedBrush="{ThemeResource ListViewItemCheckBoxSelectedBrush}"
CheckBoxSelectedDisabledBrush="{ThemeResource ListViewItemCheckBoxSelectedDisabledBrush}"
CheckBoxSelectedPointerOverBrush="{ThemeResource ListViewItemCheckBoxSelectedPointerOverBrush}"
CheckBoxSelectedPressedBrush="{ThemeResource ListViewItemCheckBoxSelectedPressedBrush}"
CheckBrush="{ThemeResource ListViewItemCheckBrush}"
CheckDisabledBrush="{ThemeResource ListViewItemCheckDisabledBrush}"
CheckMode="{ThemeResource ListViewItemCheckMode}"
CheckPressedBrush="{ThemeResource ListViewItemCheckPressedBrush}"
ContentMargin="{TemplateBinding Padding}"
ContentTransitions="{TemplateBinding ContentTransitions}"
Control.IsTemplateFocusTarget="True"
Expand All @@ -485,17 +493,10 @@
PressedBackground="{ThemeResource SettingsCardBackgroundPressed}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
SelectedBackground="{ThemeResource SettingsCardBackground}"
SelectedDisabledBackground="{ThemeResource ListViewItemBackgroundSelectedDisabled}"
SelectedForeground="{ThemeResource SettingsCardForeground}"
SelectedPointerOverBackground="{ThemeResource SettingsCardBackgroundPointerOver}"
SelectedPressedBackground="{ThemeResource SettingsCardBackgroundPressed}"
SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}"
SelectionIndicatorBrush="{ThemeResource ListViewItemSelectionIndicatorBrush}"
SelectionIndicatorCornerRadius="{ThemeResource ListViewItemSelectionIndicatorCornerRadius}"
SelectionIndicatorDisabledBrush="{ThemeResource ListViewItemSelectionIndicatorDisabledBrush}"
SelectionIndicatorPointerOverBrush="{ThemeResource ListViewItemSelectionIndicatorPointerOverBrush}"
SelectionIndicatorPressedBrush="{ThemeResource ListViewItemSelectionIndicatorPressedBrush}"
SelectionIndicatorVisualEnabled="{ThemeResource ListViewItemSelectionIndicatorVisualEnabled}" />
SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}" />
</ControlTemplate>
</Setter.Value>
</Setter>
Expand Down
11 changes: 5 additions & 6 deletions CoreAppUWP/Helpers/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using Windows.Storage;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;

namespace CoreAppUWP.Helpers
Expand Down Expand Up @@ -64,11 +64,10 @@ public static T Deserialize<T>(string value)
{
if (string.IsNullOrEmpty(value)) { return default; }
Type type = typeof(T);
return type == typeof(bool) && JsonSerializer.Deserialize(value, SourceGenerationContext.Default.Boolean) is T @bool
? @bool
: type == typeof(ElementTheme) && JsonSerializer.Deserialize(value, SourceGenerationContext.Default.ElementTheme) is T ElementTheme
? ElementTheme
: default;
return type == typeof(bool) ? Deserialize(value, SourceGenerationContext.Default.Boolean)
: type == typeof(ElementTheme) ? Deserialize(value, SourceGenerationContext.Default.ElementTheme)
: default;
static T Deserialize<TValue>(string json, JsonTypeInfo<TValue> jsonTypeInfo) => JsonSerializer.Deserialize(json, jsonTypeInfo) is T value ? value : default;
}
}

Expand Down

0 comments on commit 67ca4a0

Please sign in to comment.