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.

UInt64EntityConverter.cs 931 B

12345678910111213141516171819202122232425262728
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Globalization;
  4. namespace Discord.Net.Converters
  5. {
  6. internal class UInt64EntityConverter : JsonConverter
  7. {
  8. public static readonly UInt64EntityConverter Instance = new UInt64EntityConverter();
  9. public override bool CanConvert(Type objectType) => true;
  10. public override bool CanRead => false;
  11. public override bool CanWrite => true;
  12. public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  13. {
  14. throw new InvalidOperationException();
  15. }
  16. public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  17. {
  18. if (value != null)
  19. writer.WriteValue((value as IEntity<ulong>).Id.ToString(CultureInfo.InvariantCulture));
  20. else
  21. writer.WriteNull();
  22. }
  23. }
  24. }