MethodInfoExtensions.cs 617 B

12345678910111213141516171819202122
  1. using System.Linq;
  2. using System.Reflection;
  3. using System.Threading.Tasks;
  4. namespace Admin.Core.Extensions
  5. {
  6. public static class MethodInfoExtensions
  7. {
  8. public static bool HasAttribute<T>(this MethodInfo method)
  9. {
  10. return method.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(T)) is T;
  11. }
  12. public static bool IsAsync(this MethodInfo method)
  13. {
  14. return method.ReturnType == typeof(Task)
  15. || (method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>));
  16. }
  17. }
  18. }