Get Attributes from Method - CSharp System

CSharp examples for System:Attribute

Description

Get Attributes from Method

Demo Code


using System.Linq;
using System.Reflection;
using System.Collections.Generic;

public class Main{
        public static IEnumerable<T> GetAttributes<T>(this MemberInfo memberInfo, bool inherit = false)
        {//  www. j  ava  2 s.  c  om
            return memberInfo
                .GetCustomAttributes(typeof(T), inherit)
                .OfType<T>();
        }
}

Related Tutorials