Field Name from Enum - CSharp System

CSharp examples for System:Enum

Description

Field Name from Enum

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww w.  j a  va  2  s  . co  m*/

public class Main{
        /// <exclude/>
        public static string FieldName(this Enum value)
        {
            var attr = value.GetType().GetField(value.ToString()).GetCustomAttribute<NameFieldAttribute>();
            return attr != null ? attr.Name : null;
        }
}

Related Tutorials