refactor: json serialization

* move all converters to `App.JsonCodeGen.cs`
* use `ColorConverter` instead of parsing colors manually
This commit is contained in:
leo 2024-07-08 16:45:51 +08:00
parent 16d9b627f0
commit 7ee3db500a
No known key found for this signature in database
5 changed files with 64 additions and 50 deletions

View file

@ -28,35 +28,30 @@ namespace SourceGit.ViewModels
set;
} = WindowState.Normal;
[JsonConverter(typeof(GridLengthConverter))]
public GridLength RepositorySidebarWidth
{
get => _repositorySidebarWidth;
set => SetProperty(ref _repositorySidebarWidth, value);
}
[JsonConverter(typeof(GridLengthConverter))]
public GridLength WorkingCopyLeftWidth
{
get => _workingCopyLeftWidth;
set => SetProperty(ref _workingCopyLeftWidth, value);
}
[JsonConverter(typeof(GridLengthConverter))]
public GridLength StashesLeftWidth
{
get => _stashesLeftWidth;
set => SetProperty(ref _stashesLeftWidth, value);
}
[JsonConverter(typeof(GridLengthConverter))]
public GridLength CommitDetailChangesLeftWidth
{
get => _commitDetailChangesLeftWidth;
set => SetProperty(ref _commitDetailChangesLeftWidth, value);
}
[JsonConverter(typeof(GridLengthConverter))]
public GridLength CommitDetailFilesLeftWidth
{
get => _commitDetailFilesLeftWidth;
@ -69,18 +64,4 @@ namespace SourceGit.ViewModels
private GridLength _commitDetailChangesLeftWidth = new GridLength(256, GridUnitType.Pixel);
private GridLength _commitDetailFilesLeftWidth = new GridLength(256, GridUnitType.Pixel);
}
public class GridLengthConverter : JsonConverter<GridLength>
{
public override GridLength Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var size = reader.GetDouble();
return new GridLength(size, GridUnitType.Pixel);
}
public override void Write(Utf8JsonWriter writer, GridLength value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value.Value);
}
}
}