我有一个我需要从xml反序列化的类,它有一个枚举属性,存储为xml中的属性。有时可能会丢失此属性或将“”作为值。 如何使序列化程序处理使BorrowerResidencyType属性可以为空?
XML:
<_RESIDENCE _StreetAddress="" _City="San Jose" _State="CA" BorrowerResidencyType="" />
<_RESIDENCE _StreetAddress="" _City="San Jose" _State="CA" />
C#:
[System.CodeDom.Compiler.GeneratedCodeAttribute ( "System.Xml", "4.0.30319.17929" )]
[System.SerializableAttribute ()]
[System.Xml.Serialization.XmlTypeAttribute ( AnonymousType = true )]
public enum _RESIDENCEBorrowerResidencyType
{
/// <remarks/>
Current,
/// <remarks/>
Prior,
}
public class Test{
public string StreetAddress{get;set;}
public string City{get;set;}
[System.Xml.Serialization.XmlAttributeAttribute ()]
public _RESIDENCEBorrowerResidencyType BorrowerResidencyType{get;set;}
}
是否有另一个能够更智能地处理这种情况的库?
答案 0 :(得分:3)
可能是这样的:
public enum _RESIDENCEBorrowerResidencyType
{
[XmlEnum(Name="")]
Default = 0,
Current,
Prior
}