title: C# XmlSerializer Add an Attribute to a Field
body: <p>I want to add a custom Attribute belonging to a field</p>
  
  <p>Goal is to get the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;doc&gt;
      &lt;assembly&gt;
          &lt;name&gt;class1&lt;/name&gt;
      &lt;/assembly&gt;
      &lt;members&gt;
        &lt;member name="P:class1.clsPerson.isAlive"&gt;
              &lt;Element&gt;
              isAlive
              &lt;/Element&gt;
              &lt;Description&gt;
              Whether the object is alive or dead
              &lt;/Description&gt;
              &lt;StandardValue&gt;
              false
              &lt;/StandardValue&gt;
          &lt;/member&gt;
      &lt;/members&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>What I currently have:</p>
  
  <pre><code> using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
   using System.Xml.Serialization;
  
   namespace class1
   {
       public class clsPerson
       {
           [XmlElement(ElementName="isAlive")]
           [Description("Whether the object is alive or dead")]
           [StandardValue(false)]
           public bool isAlive { get; set; }
       }
  
       class Program
       {
           static void Main(string[] args)
           {
               clsPerson p = new clsPerson();
               p.isAlive = true;
               System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType());
               x.Serialize(Console.Out, p);
               Console.WriteLine();
               Console.ReadLine();
           }
       }
   }
  </code></pre>
  
  <p>My current Annotation classes:</p>
  
  <pre><code>using System;
  
  namespace class1
  {
      internal class StandardValueAttribute : Attribute
      {
          public readonly object DefaultValue;
  
          public StandardValueAttribute(Object defaultValue)
          {
              this.DefaultValue = defaultValue;
          }
      }
  }
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace class1
  {
      internal class DescriptionAttribute : Attribute
      {
          private string v;
  
          public DescriptionAttribute(string v)
          {
              this.v = v;
          }
      }
  }
  </code></pre>
  
  <p>How can I add my custom Attributes like  Description and StandardValue to the XMLSerializer?</p>