title: Typed wrapper for retrieving attributes in C#
body: <p>There is custom attribute that allows to declare extension of a file used for serialize some class:</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
  public sealed class FileExtensionAttribute : Attribute {  
    readonly string extension;
    readonly string description;
    public FileExtensionAttribute(string extension, string description) {
      this.extension = extension;
      this.description = description;
    }
    public string Extension { get { return extension; } }
    public string Description { get { return description; } }
    public string GetFilterString() { return string.Format("{0}|*.{1}", description, extension); }
  }
  </code></pre>
  
  <p>I marked some class with it:</p>
  
  <pre><code>[FileExtension("users", "Contestants DB")]
  public class UsersDB {
    //...
  }
  </code></pre>
  
  <p>So now I use reflection to retrieve <code>GetFilterString()</code> result:</p>
  
  <pre><code>string filter = (Attribute.GetCustomAttribute(typeof(UsersDB), typeof(FileExtensionAttribute)) as FileExtensionAttribute).GetFilterString();
  saveFileDialog.Filter = filter;
  openFileDialog.Filter = filter;
  </code></pre>
  
  <p>I want to write more expressive and less long-winded, something like this:</p>
  
  <pre><code>UsersDB.Attributes.FileExtension.GetFilterString();
  </code></pre>
  
  <p>or at least</p>
  
  <pre><code>AttributesOf(UsersDB).FileExtension.GetFilterString();
  </code></pre>
  
  <p>And I wish this syntax for any attributes and classes.</p>