|
@ -1,5 +1,6 @@ |
|
|
#nullable enable |
|
|
#nullable enable |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Runtime.Remoting.Messaging; |
|
|
using Hive.Versioning; |
|
|
using Hive.Versioning; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json; |
|
|
|
|
|
|
|
@ -8,9 +9,12 @@ namespace IPA.JsonConverters |
|
|
internal class SemverRangeConverter : JsonConverter<VersionRange?> |
|
|
internal class SemverRangeConverter : JsonConverter<VersionRange?> |
|
|
{ |
|
|
{ |
|
|
public override VersionRange? ReadJson(JsonReader reader, Type objectType, VersionRange? existingValue, bool hasExistingValue, JsonSerializer serializer) |
|
|
public override VersionRange? ReadJson(JsonReader reader, Type objectType, VersionRange? existingValue, bool hasExistingValue, JsonSerializer serializer) |
|
|
=> reader.Value is string s && VersionRange.TryParse(s, out var range) ? range : existingValue; |
|
|
|
|
|
|
|
|
=> reader.Value is not string s ? existingValue : new VersionRange(s); |
|
|
|
|
|
|
|
|
public override void WriteJson(JsonWriter writer, VersionRange? value, JsonSerializer serializer) |
|
|
public override void WriteJson(JsonWriter writer, VersionRange? value, JsonSerializer serializer) |
|
|
=> writer.WriteValue(value?.ToString()); |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
if (value is null) writer.WriteNull(); |
|
|
|
|
|
else writer.WriteValue(value.ToString()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |