You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
643 B

  1. #nullable enable
  2. using System;
  3. using Hive.Versioning;
  4. using Newtonsoft.Json;
  5. namespace IPA.JsonConverters
  6. {
  7. internal class SemverRangeConverter : JsonConverter<VersionRange?>
  8. {
  9. public override VersionRange? ReadJson(JsonReader reader, Type objectType, VersionRange? existingValue, bool hasExistingValue, JsonSerializer serializer)
  10. => reader.Value is string s && VersionRange.TryParse(s, out var range) ? range : existingValue;
  11. public override void WriteJson(JsonWriter writer, VersionRange? value, JsonSerializer serializer)
  12. => writer.WriteValue(value?.ToString());
  13. }
  14. }