title: c#: How to create serializable c# class to reflect XML file with dynamic sub-element?
body: <p>Can anyone suggest how to create a c# class to reflect the following example of XML structure please?  Basically, the sub-element within the element <em>Value</em> can contain either <em>Integer</em> or <em>String</em> elements.</p>
  
  <pre><code>&lt;Preferences&gt;
     &lt;Preference&gt;
        &lt;Tag&gt;CY3A&lt;/Tag&gt;
        &lt;Precedence&gt;XML&lt;/Precedence&gt;
        &lt;Value&gt;
           &lt;Length&gt;4&lt;/Length&gt;
           &lt;Integer&gt;0&lt;/Integer&gt;
        &lt;/Value&gt;
     &lt;/Preference&gt;    
     &lt;Preference&gt;
        &lt;Tag&gt;CYRV&lt;/Tag&gt;
        &lt;Precedence&gt;XML&lt;/Precedence&gt;
        &lt;Value&gt;
           &lt;Length&gt;16&lt;/Length&gt;
           &lt;String&gt;0000 00 @00000&lt;/String&gt;
        &lt;/Value&gt;
     &lt;/Preference&gt;
  &lt;/Preferences&gt;
  </code></pre>
  
  <p>I have tried to define the class as follows but it didn't result in what I am looking for. It generates the unwanted <em>d</em> element.</p>
  
  <pre><code>public class ProgrammingConfiguration
  {
     public int Version { get; set; }
     public preferences Preferences { get; set; }
  }
  
  public class preferences
  {
     public preference Preference { get; set; }
  }
  
  public class preference
  {
     public string Tag { get; set; }
     public string Precedence { get; set; }                                     
     public value Value { get; set; }
  }
  
  public class value
  {
     [XmlElement]
     public int Length;
  
     [XmlElement(Type = typeof(Integer)),
      XmlElement(Type = typeof(HexBinary))]
     public object datafield;
  }
  
  public class Integer
  {          
     public string d;            
  }  
  
  public class String
  {            
     public string d;
  }        
  </code></pre>