Field Value from Enum - CSharp System

CSharp examples for System:Enum

Description

Field Value from Enum

Demo Code


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

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

Related Tutorials