title: Serializing an XElement that is a property of a class object
body: <p>I've got a class that includes an XElement object...</p>
  
  <pre><code>public class SomeClass
  {
      public string prop1 = "";
      public string prop2 = "";
      public XElement elem = null;
  }
  </code></pre>
  
  <p>I'm setting the XElement property later in the code with an instance of another internally defined class object...</p>
  
  <pre><code>UserFields userFields = new UserFields();
  SomeClass sc = new SomeClass();
  sc.prop1 = "Sam";
  sc.prop2 = "Smith";
  sc.elem = new XElement("UserFields", userFields);
  </code></pre>
  
  <p>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...</p>
  
  <pre><code>StringWriter sw = new StringWriter();
  XmlSerializer x = new XmlSerializer(o.GetType());
  x.Serialize(sw, o);
  string xmlString = sw.ToString();
  </code></pre>
  
  <p>I get this as output...</p>
  
  <pre><code>&lt;SomeClass&gt;
      &lt;prop1&gt;Sam&lt;/prop1&gt;
      &lt;prop2&gt;Smith&lt;/prop2&gt;
      &lt;elem&gt;MyNamespace.UserFields&lt;/elem&gt;
  &lt;/SomeClass&gt;
  </code></pre>
  
  <p>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?</p>