title: Get custom attributes of enum value
body: <p>In a WinRT .NET application (C#) I want to get the custom attributes, that are defined on an enum value. Take the following enum for example:</p>
  
  <pre><code>public enum MyEnum
  {
      [Display(Name="Foo")]
      EnumValue1,
  
      [Display(Name="Bar")]
      EnumValue2
  }
  </code></pre>
  
  <p>Now in "normal" .NET I know that I'm able to obtain the custom attributes of an enum value with <code>enumValue.GetType().GetMember(enumValue.ToString())</code>.</p>
  
  <p>Unfortunately, in WinRT .NET the <code>GetMember()</code> method isn't available on the Type class.<br>
  Any suggestions how to go with this?</p>
  
  <p>=====================================================</p>
  
  <p>Thanks to Marc below, I found the <strong>answer</strong>!
  The following code works to get a specific custom attribute from an enum value in .NET 4.5 WinRT:</p>
  
  <pre><code>public static class EnumHelper
  {
      public static T GetAttribute&lt;T&gt;(this Enum enumValue)
          where T : Attribute
      {
          return enumValue
              .GetType()
              .GetTypeInfo()
              .GetDeclaredField(enumValue.ToString())
              .GetCustomAttribute&lt;T&gt;();
      }
  }
  </code></pre>