Advertisement
uurha

Json serialize base class

May 3rd, 2022
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. [JsonConverter(typeof(JsonSubtypes), "Sound")]
  2. [JsonSubtypes.KnownSubType(typeof(Dog), "Bark")]
  3. [JsonSubtypes.KnownSubType(typeof(Cat), "Meow")]
  4. public class Animal
  5. {
  6.     public virtual string Sound { get; }
  7.     public string Color { get; set; }
  8. }
  9.  
  10. public class Dog : Animal
  11. {
  12.     public override string Sound { get; } = "Bark";
  13.     public string Breed { get; set; }
  14. }
  15.  
  16. public class Cat : Animal
  17. {
  18.     public override string Sound { get; } = "Meow";
  19.     public bool Declawed { get; set; }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement