title: XmlSerializer - serialize property-member as attribute
body: <p>I am trying to serialize (<code>XmlSerializer</code>) all members of an inherided property as attributes.</p>
  
  <p><strong>Both classes:</strong></p>
  
  <pre><code>public class Tree
  {
      public Point Location { get; set; }
  }
  
  public class AppleTree : Tree
  {
      [XmlAttribute]
      public int FruitCount { get; set; }
  }
  </code></pre>
  
  <p><strong>Main Program:</strong></p>
  
  <pre><code>AppleTree appleTree = new AppleTree
  {
      Location = new Point(10, 20),
      FruitCount = 69
  };
  // Serialize ...
  </code></pre>
  
  <p><strong>Now I get this:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;AppleTree FruitCount="69"&gt;
    &lt;Location&gt;
      &lt;X&gt;10&lt;/X&gt;
      &lt;Y&gt;20&lt;/Y&gt;
    &lt;/Location&gt;
  &lt;/AppleTree&gt;
  </code></pre>
  
  <p>But I want all members of <code>Location</code> as attributes of <code>AppleTree</code>.
  <strong>Like that:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;AppleTree FruitCount="69" X="10" Y="20" /&gt;
  </code></pre>
  
  <p><strong>I know, I could to something like:</strong></p>
  
  <pre><code>public class Tree
  {
      [XmlIgnore]
      public Point Location { get; set; }
  }
  
  public class AppleTree : Tree
  {
      [XmlAttribute]
      public int FruitCount { get; set; }
  
      [XmlAttribute]
      public int X
      {
          get { return Location.X; }
          set { Location = new Point(value, Location.Y); }
      }
  
      [XmlAttribute]
      public int Y
      {
          get { return Location.Y; }
          set { Location = new Point(Location.X, value); }
      }
  }
  </code></pre>
  
  <p>But I don't want to have duplicates of all properties (This is just a simple example).</p>
  
  <p>So is there another solution? Perhaps with attributes of <code>XmlSerializer</code>?</p>