我知道我可以使用[JsonIgnore]
从序列化中排除属性,但是在我当前的用例中,如果我只是告诉序列化程序应该包含哪些属性(没有数量很少,但将来也不会改变。
所以我想知道,是否有相反的机制可以包含我需要的属性?我当时在想也许可以使用接口或其他东西,但是我不确定如何处理。我一路上需要原始的 big 对象,但仅应序列化其 lite 版本。我将如何方便实现这一目标?
class Car
{
[JsonInclude] // There is no such attribute but maybe another trick?
public string Make { get; set; }
public string MakeFormatted => Make.ToUpper().ToLower(); // anything
}