How to extend XmlAttribute Behavior?
How to extend XmlAttribute class?
Using the below code, I've made my nullable property to be serializable and gets excluded from serialization if there is no value:
[XmlIgnore]
public DateTime? LastUpdated { get; set; }
[XmlAttribute("lastUpdated")]
public DateTime LastUpdatedSerializable
{
get { return this.LastUpdated.Value; }
set { this.LastUpdated = value; }
}
public bool ShouldSerializeLastUpdatedSerializable()
{
return LastUpdated.HasValue;
}
Instead of above, I'd like to be able to use the below code to achieve the same result:
[XmlAttribute("lastUpdated", IsNullable = true)]
public DateTime? LastUpdatedSerializable
{
get;
set;
}
Therefore, I'd like to be able to extend the XmlAttribute to accept a property called IsNullable then if the value is true, it should replace the implementation with the above codes so that if there is no value then the node be excluded.
It's something that Microsoft should have added to .NET Framework really for XmlAttribute.
How to achieve it?
链接地址: http://www.djcxy.com/p/65140.html上一篇: XMLSerializer并创建一个具有属性的XML Array
下一篇: 如何扩展XmlAttribute行为?