This used used to work with earlier version of .Net. What's the equivalent in .net core terms. Now I get following error:
'ActionDescriptor' does not contain a definition for 'GetCustomAttributes' and no extension method 'GetCustomAttributes' accepting a first argument of type 'ActionDescriptor' could be found
public virtual void SetupMetadata(ActionExecutingContext filterContext)
{
var myAttr = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MyAttribute), false);
if (myAttr.Length == 1)
//do something
}
Attribute definition:
public class MyAttribute : Attribute
{
private readonly string _parameter;
public PageTitleAttribute(string parameter)
{
_parameter = parameter;
}
public string Parameter { get { return _parameter; } }
}
Code Usage:
[MyAttribute("Attribute value is set here")]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
ControllerActionDescriptor.Parameters
toControllerParameterDescriptor
which has aParameterInfo
for all the usual reflection information. – Mickel