|
1 | | -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Text.Json; |
2 | 3 | using System.Text.Json.Serialization; |
3 | 4 |
|
| 5 | +using Avalonia.Controls; |
| 6 | +using Avalonia.Media; |
| 7 | + |
4 | 8 | namespace SourceGit |
5 | 9 | { |
6 | | - [JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)] |
7 | | - [JsonSerializable(typeof(List<Models.InteractiveRebaseJob>))] |
| 10 | + public class ColorConverter : JsonConverter<Color> |
| 11 | + { |
| 12 | + public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 13 | + { |
| 14 | + return Color.Parse(reader.GetString()); |
| 15 | + } |
| 16 | + |
| 17 | + public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options) |
| 18 | + { |
| 19 | + writer.WriteStringValue(value.ToString()); |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + public class FontFamilyConverter : JsonConverter<FontFamily> |
| 24 | + { |
| 25 | + public override FontFamily Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 26 | + { |
| 27 | + var name = reader.GetString(); |
| 28 | + return new FontFamily(name); |
| 29 | + } |
| 30 | + |
| 31 | + public override void Write(Utf8JsonWriter writer, FontFamily value, JsonSerializerOptions options) |
| 32 | + { |
| 33 | + writer.WriteStringValue(value.ToString()); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public class GridLengthConverter : JsonConverter<GridLength> |
| 38 | + { |
| 39 | + public override GridLength Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 40 | + { |
| 41 | + var size = reader.GetDouble(); |
| 42 | + return new GridLength(size, GridUnitType.Pixel); |
| 43 | + } |
| 44 | + |
| 45 | + public override void Write(Utf8JsonWriter writer, GridLength value, JsonSerializerOptions options) |
| 46 | + { |
| 47 | + writer.WriteNumberValue(value.Value); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + [JsonSourceGenerationOptions( |
| 52 | + WriteIndented = true, |
| 53 | + IgnoreReadOnlyFields = true, |
| 54 | + IgnoreReadOnlyProperties = true, |
| 55 | + Converters = [ |
| 56 | + typeof(ColorConverter), |
| 57 | + typeof(FontFamilyConverter), |
| 58 | + typeof(GridLengthConverter), |
| 59 | + ] |
| 60 | + )] |
| 61 | + [JsonSerializable(typeof(Models.InteractiveRebaseJobCollection))] |
8 | 62 | [JsonSerializable(typeof(Models.JetBrainsState))] |
| 63 | + [JsonSerializable(typeof(Models.ThemeOverrides))] |
9 | 64 | [JsonSerializable(typeof(Models.Version))] |
10 | | - [JsonSerializable(typeof(Models.CustomColorSchema))] |
11 | 65 | [JsonSerializable(typeof(ViewModels.Preference))] |
12 | 66 | [JsonSerializable(typeof(ViewModels.RepositorySettings))] |
13 | 67 | internal partial class JsonCodeGen : JsonSerializerContext { } |
|
0 commit comments