I've got a class that includes an XElement object...
public class SomeClass
{
public string prop1 = "";
public string prop2 = "";
public XElement elem = null;
}
I'm setting the XElement property later in the code with an instance of another internally defined class object...
UserFields userFields = new UserFields();
SomeClass sc = new SomeClass();
sc.prop1 = "Sam";
sc.prop2 = "Smith";
sc.elem = new XElement("UserFields", userFields);
The problem is that when I use XmlSerializer to serialize the class objects to XML, I'm only getting the fully qualified class name for the SomeClass.elem property...
StringWriter sw = new StringWriter();
XmlSerializer x = new XmlSerializer(o.GetType());
x.Serialize(sw, o);
string xmlString = sw.ToString();
I get this as output...
<SomeClass>
<prop1>Sam</prop1>
<prop2>Smith</prop2>
<elem>MyNamespace.UserFields</elem>
</SomeClass>
It seems like the XmlSerializer doesn't know quite what to do with the XElement object. I'd like to find a way to get the XML out of the XElement object serialized as an XML string like is happening with the other class object. Any ideas?