0
我使用YamlDotNet序列化對象和引用和值類型。我期望完成的是我的整數值零保留在輸出的yaml中,但空值將被丟棄。 EmitDefaults看起來爲數值放棄'0'。我明白null是引用類型的默認值。 Json.Net解決了這個破與它分爲以下幾個特性:YamlDotNet SerializationOptions.EmitDefaults行爲
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
有什麼辦法來完成以下?
class foo
{
int index {get;set;}
string bar {get;set;}
}
new foo { index =0; bar = null }
would yield the following yaml:
index: 0
new foo { index =0; bar = "bar" }
would yield the following yaml:
index: 0
bar: bar
感謝