title: Serialize class variable as xml without creating a new element
body: <p>I have two classes, A and B. A has an instance of B, and when serializing A, I want B to be at the same level as A and not a sub element.</p>
  
  <p>So I want the resulting xml to become</p>
  
  <pre>
      &lt;a&gt;
        &lt;avalue&gt;a&lt;/avalue&gt;
        &lt;bvalue&gt;b&lt;/bvalue&gt;
      &lt;/a&gt;
  </pre>
  
  <p>This program puts B in it's own element as</p>
  
  <pre>
      &lt;a&gt;
        &lt;avalue&gt;a&lt;/avalue&gt;
        &lt;b&gt;
          &lt;bvalue&gt;b&lt;/bvalue&gt;
        &lt;/b&gt;
      &lt;/a&gt;
  </pre>
  
  <pre><code>public class A
  {
      public string avalue = "a";
      public B b = new B();
  }
  
  public class B
  {
      public string bvalue = "b";
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var a = new A();
          var xml = new XmlSerializer(a.GetType());
          xml.Serialize(new StreamWriter(@"c:\temp\tmp.xml"), a);
      }
  }
  </code></pre>
  
  <p>PS: This must have been asked before, but I'm not sure what to search for. My google-fu turns up empty...</p>
  
  <p>Edit:</p>
  
  <p>And I'm hoping to avoid the "wrapper" solution if possible:</p>
  
  <pre><code>public class A
  {
      public string avalue = "a";
  
      [XmlIgnore]
      public B b { get; set; }
  
      [XmlElement("bvalue")]
      public string bvalue
      {
          get { return b.bvalue; }
          set { b.bvalue = value;  }
      }
  }
  </code></pre>