Sunday, August 4, 2013

LINQ to XML - subclassing XElement

You should use encapsulation, rather than inheritance here.



class TopLevelBlock
{
readonly XElement doc;

TopLevelBlock(string name)
{
doc = new XElement((XName)name);
doc.SetAttributeValue("someAttribute","");

}

public int someAttribute
{
get
{
return int.Parse(doc.Attribute("someAttribute").Value);
}
set
{
doc.SetAttributeValue("someAttribute", value.ToString());
}
}
}



Or perhaps XML Serialization.


David




David http://blogs.msdn.com/b/dbrowne/


No comments:

Post a Comment