MaskConverter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using Newtonsoft.Json;
  3. namespace Masuit.Tools.Systems;
  4. public class MaskConverter:JsonConverter
  5. {
  6. /// <summary>Writes the JSON representation of the object.</summary>
  7. /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
  8. /// <param name="value">The value.</param>
  9. /// <param name="serializer">The calling serializer.</param>
  10. public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  11. {
  12. writer.WriteValue(value?.ToString().Mask());
  13. }
  14. /// <summary>Reads the JSON representation of the object.</summary>
  15. /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
  16. /// <param name="objectType">Type of the object.</param>
  17. /// <param name="existingValue">The existing value of object being read.</param>
  18. /// <param name="serializer">The calling serializer.</param>
  19. /// <returns>The object value.</returns>
  20. public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  21. {
  22. return reader.Value;
  23. }
  24. /// <summary>
  25. /// Determines whether this instance can convert the specified object type.
  26. /// </summary>
  27. /// <param name="objectType">Type of the object.</param>
  28. /// <returns>
  29. /// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
  30. /// </returns>
  31. public override bool CanConvert(Type objectType)
  32. {
  33. return true;
  34. }
  35. }