Mega Code Archive

 
Categories / C# / Reflection
 

Get Methods With Attribute

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace RestCake.Util {     internal static class ReflectionHelper     {         public static IEnumerable<MethodInfo> GetMethodsWithAttribute(Type classType, Type attributeType)         {             return classType.GetMethods().Where(methodInfo => methodInfo.GetCustomAttributes(attributeType, true).Length > 0);         }         public static IEnumerable<MemberInfo> GetMembersWithAttribute(Type classType, Type attributeType)         {             return classType.GetMembers().Where(memberInfo => memberInfo.GetCustomAttributes(attributeType, true).Length > 0);         }     } }