forked from unitycoder/UnityLauncherPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityVersion.cs
More file actions
35 lines (32 loc) · 1.19 KB
/
Copy pathUnityVersion.cs
File metadata and controls
35 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace UnityLauncherPro
{
public class UnityVersion
{
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("stream")]
[JsonConverter(typeof(UnityVersionStreamConverter))]
public UnityVersionStream Stream { get; set; }
[JsonPropertyName("releaseDate")]
public DateTime ReleaseDate { get; set; }
}
public class UnityVersionStreamConverter : JsonConverter<UnityVersionStream>
{
public override UnityVersionStream Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string streamString = reader.GetString();
if (Enum.TryParse<UnityVersionStream>(streamString, true, out var result))
{
return result;
}
throw new JsonException($"Unable to convert \"{streamString}\" to UnityVersionStream");
}
public override void Write(Utf8JsonWriter writer, UnityVersionStream value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString().ToUpper());
}
}
}