title: XML Element Name from T in Generic Class
body: <p>For a current project I am trying to make have a generic <code>XML</code> creator using the <code>XmlSerializer</code> class - I need a certain element in one of the classes to have the <code>ElementName</code> set based on the type of class that the creator is in in this context that is simple enough. Here is an example:</p>
  
  <pre><code>  public abstract class ElementTypeBase
    {
      public abstract string ElementName { get; }
    }
    public class ElementTypeA : ElementTypeBase
    {
      public override string ElementName
      {
        get { return "ElementA"; }
      }
    }
  </code></pre>
  
  <p>Then pass this to my <code>XML</code> object class which will be used for the <code>XmlSerializer</code> but I want the <code>ElementName</code> to be specific to the type.</p>
  
  <pre><code>  public class XMLObject&lt;T&gt; where T : ElementTypeBase
    {
      [XmlElement(Activator.CreateInstance&lt;T&gt;().ElementName)]
      public string SomeElement;
    }
  </code></pre>
  
  <p>I thought I would be able to do that but get:</p>
  
  <blockquote>
    <p>An attribute argument must be a constant expression, typeof expression
    or array creation expression of an attribute parameter type</p>
  </blockquote>
  
  <p>So I thought that I could <code>override ToString()</code> but this doesn't work, I was thinking of using constants but it feels dirty. Any other suggestions?</p>