How does Linq-to-Xml convert objects to strings?
- by Eamon Nerbonne
Linq-to-Xml contains lots of methods that allow you to add arbitrary objects to an xml tree. These objects are converted to strings by some means, but I can't seem to find the specification of how this occurs. The conversion I'm referring to is mentioned (but not specified) in MSDN.
I happen to need this for javascript interop, but that doesn't much matter to the question.
Linq to Xml isn't just calling .ToString(). Firstly, it'll accept null elements, and secondly, it's doing things no .ToString() implementation does:
For example:
new XElement("elem",true).ToString() == "<elem>true</elem>"
//but...
true.ToString() == "True" //IIRC, this is culture invariant, but in any case...
true.ToString(CultureInfo.InvariantCulture) == "True"
Other basic data types are similarly specially treated.
So, does anybody know what it's doing and where that's described?