This piece can be used as en extension method on every enum. As generic parameter T you should use the type of the attribute you want to get from the enum.

Note
* The attribute you want to get has to be set on the enum.
* You should always be precise with the type of generic parameter T, to get exactly the Attribute you desire.
* On enums with the Flag attribute set, this method will not work everytime.

Example: By passing “Attribute” as parameter T you will get a InvalidCastException if the DescriptionAttribute is set. It has also no sense to pass “Attribute” because then, in the best case, you will get the first attribute that is set on the enum.

Please be avare of using flags on enums when you call GetArrtibute().
The problem is of its internal nature. The values the fields in the flag enum has to be of power of 2.
Therefore considering the example above, if you set flag Jannuary | February the resulting value is 3, but 3 is not defined as a value in the bitfield.
Therefore it doesn’t exist a description for value 3.