Is there any possible way to serialize dynamically created object to an xml string?
var foobar = new { foo = "bar" };
string xml = ConvertToXMLString(foobar);
//xml should be something like :
//<foo>bar</foo>
I was able to take a look at XMLSerializer and DataContractSerializer but XMLSerializer requires the object type while DataContractSerializer requires attribute on the properties that needs to be serialized.
Out of desperation, I converted the object to JSON first and from JSON converted it to XML.
var foobar = new { foo = "bar" };
JavaScriptSerializer js = new JavaScriptSerializer();
jsonString = js.Serialize(values);
//Json.NET at http://json.codeplex.com/
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonString);