title: Override MVC Model Display Name Annotation with Custom Functionality
body: <p>I have the following method where I read from a key-value XML file. I pass in a key and am returned a value where I used to display on my view. </p>
  
  <pre><code>public static class TextManager
  {
      public static string GetValue(string key)
      {
          string returnVal = null; 
          XmlSerializer serializer = new XmlSerializer(typeof(Entries));
          string path = HttpContext.Current.Server.MapPath("/App_Data/text-key-value.xml");
          if (File.Exists(path))
          {
              Entries entries = (Entries)serializer.Deserialize(File.OpenRead(path));
              var entry = entries.Where(u =&gt; u.Key == key).FirstOrDefault();
              if (entry != null)
              {
                  returnVal = entry.Value;
              }
          }
          return returnVal;
      }
  }
  </code></pre>
  
  <p>Basically I want to be able to use this method in my model class as a data-annotation that will pull directly from my site text file and set to the display name property. </p>
  
  <p>For instance I want to replace</p>
  
  <pre><code>[Display(Name = "Reference Code")]
  public string ReferenceCode { get; set; }
  </code></pre>
  
  <p>With this</p>
  
  <pre><code>[DisplaySiteText("ReferenceCodeKey")]
  public string ReferenceCode { get; set; }
  </code></pre>
  
  <p>DisplaySiteText would pass the string reference "ReferenceCodeKey" to the GetValue method, file the reference in the file and then set the standard Display name attribute to whatever was in the file. </p>
  
  <p>How do I create my own custom model annotation to do this, I've written custom validation annotations in the past by creating a class that inherits from ValidationAttribute, but I don't think that will work in this case. </p>