by
192 12
1
6
6,506
2
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Specified
Popularity: 1016th place
This snippet is Public
.NETFramework3.5
InputName0value
InputType0T
LanguageCSharp
LicenseMIT_X11
MethodNameGetEnumDescription
OutputTypestring

C#: Get Enum description attribute

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1069/C---Get-Enum-description-attribute?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static string GetEnumDescription<T>(T value) { FieldInfo fi = value.GetType().GetField(value.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes( typeof(DescriptionAttribute), false ); if (attributes != null && attributes.Length > 0) { return attributes[0].Description; } else { return value.ToString(); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus