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.

20 lines
731 B

  1. #nullable enable
  2. using System;
  3. using Hive.Versioning;
  4. using System.Text.Json;
  5. using System.Text.Json.Serialization;
  6. namespace IPA.JsonConverters
  7. {
  8. internal class SemverRangeConverter : JsonConverter<VersionRange?>
  9. {
  10. public override VersionRange? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
  11. => reader.TokenType is not JsonTokenType.String ? null : new VersionRange(reader.GetString()!);
  12. public override void Write(Utf8JsonWriter writer, VersionRange? value, JsonSerializerOptions options)
  13. {
  14. if (value is null) writer.WriteNullValue();
  15. else writer.WriteStringValue(value.ToString());
  16. }
  17. }
  18. }