我需要将下面的YAML反序列化为我的自定义类型。YamlAlias属性似乎过时了,所以我用YamlMember替换了它。除以下例外情况外,反序列化下列YAML失败:
System.Runtime.Serialization.SerializationException host: properties: mem\_size: 2048 MB YamlDotNet.Core.YamlException:(行: 21,Col: 13,Idx: 524) -(行: 21,Col: 13,Idx: 524):反序列化期间的异常->YamlDotNet.Core.YamlException:属性'mem_size‘在类型'Toscana.Domain.HostProperties’上找不到。
public class Host
{
public HostProperties Properties { get; set; }
}
public class HostProperties
{
[YamlMember(typeof(DigitalStorage))]
public string MemSize { get; set; }
}发布于 2016-06-14 10:27:13
Alias是YamlMemberAttribute类的一个属性,它不在构造函数中。现在,我不知道您的DigitalStorage类是什么样子,也不知道是否会成功地将string反序列化到其中(我对此表示怀疑),但由于您的问题是添加别名,所以您可以这样做:
public class HostProperties
{
[YamlMember(typeof(DigitalStorage), Alias = "mem_size")]
public string MemSize { get; set; }
}https://stackoverflow.com/questions/37639619
复制相似问题