hi,
I would like to subclass XElement to add a bit of stronger type checking when I am constructing a document. Unfortunately I found to be locked out of the important part of the library.
// only illustrative
class TopLevelBlock : XElement {
TopLevelBlock(XName name) : base(name) {}
}
class Parargaph : TopLevelBLock {
Paragraph() : base(W.p) {}
// not possible due to internal restriction
// public override XNode CloneNode() {
// return new Paragraph(this);
// }
}
class Table : TopLevelBlock {
}
class StructuredDocumentTag : TopLevelBlock {
}
para = Paragraph();
parent.Add(para); // it will stay as Paragraph
parent.Add(para); // as a result of CloneNode type will change to XElement
Everything is fine as long as I am constructing document and not calling any LINQ transformations triggering CloneNode. As soon as I hit CloneNode, everything gets downgraded to XElement.
The CloneNode is marked already as virtual, but unfortunately internal. Is there any chance to relax this restriction in the future?
Perhaps there is a better way of accomplishing what I am trying to do using other mechanism of c#/.net. Any suggestions are welcome.
--pawel
Other people reported similar difficulties when subclassing XText, http://blogs.msdn.com/b/ericwhite/archive/2010/01/21/writing-entity-references-using-linq-to-xml.aspx
No comments:
Post a Comment