]> fortfriendship.online Git - gnargle.github.io.git/blob - SiteTools/ParticleGen/ParticleClasses.cs
new blog post omg
[gnargle.github.io.git] / SiteTools / ParticleGen / ParticleClasses.cs
1 // <auto-generated />
2 //
3 // To parse this JSON data, add NuGet 'System.Text.Json' then do:
4 //
5 // using ParticleGen;
6 //
7 // var particleRoot = ParticleRoot.FromJson(jsonString);
8 #nullable enable
9 #pragma warning disable CS8618
10 #pragma warning disable CS8601
11 #pragma warning disable CS8603
12
13 namespace ParticleGen
14 {
15 using System;
16 using System.Collections.Generic;
17
18 using System.Text.Json;
19 using System.Text.Json.Serialization;
20 using System.Globalization;
21
22 public partial class ParticleRoot
23 {
24 [JsonPropertyName("format")]
25 public string Format { get; set; }
26
27 [JsonPropertyName("title")]
28 public string Title { get; set; }
29
30 [JsonPropertyName("content")]
31 public List<Content> Content { get; set; }
32 }
33
34 public partial class Content
35 {
36 [JsonPropertyName("type")]
37 public string Type { get; set; }
38
39 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
40 [JsonPropertyName("text")]
41 public string Text { get; set; }
42
43 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
44 [JsonPropertyName("style")]
45 public Style Style { get; set; }
46
47 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
48 [JsonPropertyName("width")]
49 public long? Width { get; set; }
50
51 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
52 [JsonPropertyName("height")]
53 public long? Height { get; set; }
54
55 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
56 [JsonPropertyName("pixels")]
57 public string Pixels { get; set; }
58
59 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
60 [JsonPropertyName("label")]
61 public string Label { get; set; }
62
63 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
64 [JsonPropertyName("action")]
65 public string Action { get; set; }
66 }
67
68 public partial class Style
69 {
70 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
71 [JsonPropertyName("text-align")]
72 public string TextAlign { get; set; }
73
74 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
75 [JsonPropertyName("scale")]
76 public long? Scale { get; set; }
77 }
78
79 public partial class ParticleRoot
80 {
81 public static ParticleRoot FromJson(string json) => JsonSerializer.Deserialize<ParticleRoot>(json, ParticleGen.Converter.Settings);
82 }
83
84 public static class Serialize
85 {
86 public static string ToJson(this ParticleRoot self) => JsonSerializer.Serialize(self, ParticleGen.Converter.Settings);
87 }
88
89 internal static class Converter
90 {
91 public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
92 {
93 Converters =
94 {
95 new DateOnlyConverter(),
96 new TimeOnlyConverter(),
97 IsoDateTimeOffsetConverter.Singleton
98 },
99 };
100 }
101
102 public class DateOnlyConverter : JsonConverter<DateOnly>
103 {
104 private readonly string serializationFormat;
105 public DateOnlyConverter() : this(null) { }
106
107 public DateOnlyConverter(string? serializationFormat)
108 {
109 this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
110 }
111
112 public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
113 {
114 var value = reader.GetString();
115 return DateOnly.Parse(value!);
116 }
117
118 public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
119 => writer.WriteStringValue(value.ToString(serializationFormat));
120 }
121
122 public class TimeOnlyConverter : JsonConverter<TimeOnly>
123 {
124 private readonly string serializationFormat;
125
126 public TimeOnlyConverter() : this(null) { }
127
128 public TimeOnlyConverter(string? serializationFormat)
129 {
130 this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
131 }
132
133 public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
134 {
135 var value = reader.GetString();
136 return TimeOnly.Parse(value!);
137 }
138
139 public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
140 => writer.WriteStringValue(value.ToString(serializationFormat));
141 }
142
143 internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
144 {
145 public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
146
147 private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
148
149 private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
150 private string? _dateTimeFormat;
151 private CultureInfo? _culture;
152
153 public DateTimeStyles DateTimeStyles
154 {
155 get => _dateTimeStyles;
156 set => _dateTimeStyles = value;
157 }
158
159 public string? DateTimeFormat
160 {
161 get => _dateTimeFormat ?? string.Empty;
162 set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
163 }
164
165 public CultureInfo Culture
166 {
167 get => _culture ?? CultureInfo.CurrentCulture;
168 set => _culture = value;
169 }
170
171 public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
172 {
173 string text;
174
175
176 if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
177 || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
178 {
179 value = value.ToUniversalTime();
180 }
181
182 text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
183
184 writer.WriteStringValue(text);
185 }
186
187 public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
188 {
189 string? dateText = reader.GetString();
190
191 if (string.IsNullOrEmpty(dateText) == false)
192 {
193 if (!string.IsNullOrEmpty(_dateTimeFormat))
194 {
195 return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
196 }
197 else
198 {
199 return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
200 }
201 }
202 else
203 {
204 return default(DateTimeOffset);
205 }
206 }
207
208
209 public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
210 }
211 }
212 #pragma warning restore CS8618
213 #pragma warning restore CS8601
214 #pragma warning restore CS8603