Browse Source

Fix SemVer converters to throw when the value is not valid

pull/72/head
Anairkoen Schno 3 years ago
parent
commit
eaab81db0b
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
2 changed files with 7 additions and 3 deletions
  1. +6
    -2
      IPA.Loader/JsonConverters/SemverRangeConverter.cs
  2. +1
    -1
      IPA.Loader/JsonConverters/SemverVersionConverter.cs

+ 6
- 2
IPA.Loader/JsonConverters/SemverRangeConverter.cs View File

@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Runtime.Remoting.Messaging;
using Hive.Versioning;
using Newtonsoft.Json;
@ -8,9 +9,12 @@ namespace IPA.JsonConverters
internal class SemverRangeConverter : JsonConverter<VersionRange?>
{
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)
=> writer.WriteValue(value?.ToString());
{
if (value is null) writer.WriteNull();
else writer.WriteValue(value.ToString());
}
}
}

+ 1
- 1
IPA.Loader/JsonConverters/SemverVersionConverter.cs View File

@ -8,7 +8,7 @@ namespace IPA.JsonConverters
internal class SemverVersionConverter : JsonConverter<Version?>
{
public override Version? ReadJson(JsonReader reader, Type objectType, Version? existingValue, bool hasExistingValue, JsonSerializer serializer)
=> reader.Value is string s && Version.TryParse(s, out var version) ? version : existingValue;
=> reader.Value is not string s ? existingValue : new Version(s);
public override void WriteJson(JsonWriter writer, Version? value, JsonSerializer serializer)
{


Loading…
Cancel
Save