Get Attribute From Enum Type - CSharp System

CSharp examples for System:Attribute

Description

Get Attribute From Enum Type

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w  w w .j  ava 2s  . c  om*/

public class Main{
        public static T GetAttributeFromEnumType<T>(this Type type, object value) where T : Attribute
        {
            var field = type.GetField(value.ToString());
            return (T)Attribute.GetCustomAttribute(field, typeof(T));
        }
}

Related Tutorials