【发布时间】:2017-01-23 09:55:24
【问题描述】:
这曾经用于早期版本的 .Net。 .net 核心术语中的等价物是什么。现在我收到以下错误:
“ActionDescriptor”不包含“GetCustomAttributes”的定义,并且找不到接受“ActionDescriptor”类型的第一个参数的扩展方法“GetCustomAttributes” p>
public virtual void SetupMetadata(ActionExecutingContext filterContext)
{
var myAttr = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MyAttribute), false);
if (myAttr.Length == 1)
//do something
}
属性定义:
public class MyAttribute : Attribute
{
private readonly string _parameter;
public PageTitleAttribute(string parameter)
{
_parameter = parameter;
}
public string Parameter { get { return _parameter; } }
}
代码用法:
[MyAttribute("Attribute value is set here")]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
【问题讨论】:
标签: c# .net asp.net-core