title: XML Serialization to child nodes without a new object
body: <p>I am using xml serialization, with rectangles but this is producing some nasty XML...</p>
  
  <p>My class is something like this:</p>
  
  <pre><code>    [Serializable]
      public class myObject
      {
         public Rectangle Region { get; set; }
  
         //Some other properties and methods...
      }
  </code></pre>
  
  <p>and that give me this when i serialize it to XML:</p>
  
  <pre><code>    &lt;myObject&gt;
        &lt;Region&gt;
          &lt;Location&gt;
            &lt;X&gt;141&lt;/X&gt;
            &lt;Y&gt;93&lt;/Y&gt;
          &lt;/Location&gt;
          &lt;Size&gt;
            &lt;Width&gt;137&lt;/Width&gt;
            &lt;Height&gt;15&lt;/Height&gt;
          &lt;/Size&gt;
          &lt;X&gt;141&lt;/X&gt;
          &lt;Y&gt;93&lt;/Y&gt;
          &lt;Width&gt;137&lt;/Width&gt;
          &lt;Height&gt;15&lt;/Height&gt;
        &lt;/Region&gt;
        ...
      &lt;/myObject&gt;
  </code></pre>
  
  <p>Yuck!</p>
  
  <p>I am hoping that I can either suppress the <code>Size</code> and <code>Location</code> properties on the <code>Rectangle</code>, or perhaps use backing variables and <code>[XmlIgnore]</code> to  end up with something like this:</p>
  
  <pre><code>    [Serializable]
      public class myObject
      {
         [XmlElement("????")]
         public int RegionX;
  
         [XmlElement("????")]
         public int RegionY;
  
         [XmlElement("????")]
         public int RegionHeight;
  
         [XmlElement("????")]
         public int RegionWidth;
  
         [XmlIgnore]
         public Rectangle Region {get { return new Rectangle(RegionX, RegionY, RegionWidth, RegionHeight);}
  
         //Some other properties and methods...
      }
  </code></pre>
  
  <p>hopefully giving me something like:</p>
  
  <pre><code>    &lt;myObject&gt;
        &lt;Region&gt;
          &lt;X&gt;141&lt;/X&gt;
          &lt;Y&gt;93&lt;/Y&gt;
          &lt;Width&gt;137&lt;/Width&gt;
          &lt;Height&gt;15&lt;/Height&gt;
        &lt;/Region&gt;
        ...
      &lt;/myObject&gt;
  </code></pre>
  
  <p>Not so good in the code, but the XML will be edited by people so it would be good to get something which works there...</p>
  
  <p>Any ides what might go in the "????"? or another way of doing this?</p>
  
  <p>I would prefer not to have to implement my own version of <code>Rectangle</code>...</p>