鉴于网上的此类文章讲的不那么好,特在此重新讲一下
创建一个.Net Core控制台程序,本文代码需要Nuget包Newtonsoft。安装后就可以开始了
首先交代一下使用的类
public abstract class EntityBase { public virtual long Id { get; set; } } public class Entity : EntityBase { public override long Id { get; set; } public string Name { get; set; } [MyJsonIgnore] public decimal Money { get; set; } public Category Category { get; set; } public List<Child> Children { get; set; } } public class Child : EntityBase { public string Name { get; set; } } public enum Category { Human = 0, Cat = 1, Dog = 2 }