PdfRpt.Core.Helper.PropertyDataAnnotations.GetEnumStringValue C# (CSharp) Méthode

GetEnumStringValue() public static méthode

Getting string attribute of Enum's value. Processing order is checking DisplayNameAttribute first and then DescriptionAttribute. If none of these is available, value.ToString() will be returned.
public static GetEnumStringValue ( this value ) : string
value this enum value
Résultat string
        public static string GetEnumStringValue(this Enum value)
        {
            var info = value.GetType().GetField(value.ToString());

            var displayName = info.GetCustomAttributes(true).OfType<DisplayNameAttribute>().FirstOrDefault();
            if (displayName != null) return displayName.DisplayName;

            var description = info.GetCustomAttributes(true).OfType<DescriptionAttribute>().FirstOrDefault();
            if (description != null) return description.Description;

            return value.ToString();
        }