Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    I like this one more than Scott's, because the usage is cleaner here (less typing), so +1 :) Commented Jun 8, 2013 at 23:10
  • 3
    If no attribute exists, wouldn't this throw a IndexOutOfRangeException? Commented Jul 20, 2013 at 0:14
  • 8
    better use type.GetMember(Enum.GetName(type, enumVal)) for the memInfo as enumVal.ToString() may not be reliable for different locales. Commented Mar 20, 2015 at 1:02
  • 5
    What is the point of calling GetCustomAttributes() then get first element instead of calling GetCustomAttribute() ? Commented Feb 24, 2017 at 12:09
  • 6
    @tigrou this extension was added quite recently to the .NET framework; the solution (which is from 2009) might need an update. Commented Aug 20, 2017 at 19:00