views:

234

answers:

2

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?

A: 

Although I can't find MSDN documentation to support this, when you do something like new XElement("bla",false) the System.Xml.XmlConvert class is uses to (de-)serialize the data in a non-localized fashion.

In other words, if anyone else needs to know what exactly linq to xml does when you add a (non-xml) object into an xml tree, look at System.Xml.XmlConvert.

Eamon Nerbonne
A: 
Euro Micelli