Last active
July 20, 2018 18:16
-
-
Save lfgrando/9febb1adbaaaa3a5d883ccb60f1bae38 to your computer and use it in GitHub Desktop.
Goldplated edition, works on MVC5, probably 4/3:filterContext.HasMarkerAttribute<RequireHttpsAttribute>()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
namespace Core.Extensions | |
{ | |
public static class MarkerAttributeExtension | |
{ | |
public static bool HasMarkerAttribute<T>(this AuthorizationContext that) | |
{ | |
return that.Controller.HasMarkerAttribute<T>() | |
|| that.ActionDescriptor.HasMarkerAttribute<T>(); | |
} | |
public static bool HasMarkerAttribute<T>(this ActionExecutingContext that) | |
{ | |
return that.Controller.HasMarkerAttribute<T>() | |
|| that.ActionDescriptor.HasMarkerAttribute<T>(); | |
} | |
public static bool HasMarkerAttribute<T>(this ControllerBase that) | |
{ | |
return that.GetType().HasMarkerAttribute<T>(); | |
} | |
public static bool HasMarkerAttribute<T>(this Type that) | |
{ | |
return that.IsDefined(typeof(T), false); | |
} | |
public static IEnumerable<T> GetCustomAttributes<T>(this Type that) | |
{ | |
return that.GetCustomAttributes(typeof(T), false).Cast<T>(); | |
} | |
public static bool HasMarkerAttribute<T>(this ActionDescriptor that) | |
{ | |
return that.IsDefined(typeof(T), false); | |
} | |
public static IEnumerable<T> GetCustomAttributes<T>(this ActionDescriptor that) | |
{ | |
return that.GetCustomAttributes(typeof(T), false).Cast<T>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment