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

OptionalPropertyConverter.cs 713 B

1234567891011121314151617181920212223
  1. using System.Text.Json;
  2. namespace Discord.Serialization.Converters
  3. {
  4. internal class OptionalPropertyConverter<T> : IPropertyConverter<Optional<T>>
  5. {
  6. private readonly IPropertyConverter<T> _innerConverter;
  7. public OptionalPropertyConverter(IPropertyConverter<T> innerConverter)
  8. {
  9. _innerConverter = innerConverter;
  10. }
  11. public Optional<T> ReadJson(JsonReader reader, bool read = true)
  12. => new Optional<T>(_innerConverter.ReadJson(reader, read));
  13. public void WriteJson(JsonWriter writer, Optional<T> value)
  14. {
  15. if (value.IsSpecified)
  16. _innerConverter.WriteJson(writer, value.Value);
  17. }
  18. }
  19. }