Ros*_*ied 8 c# reflection attributes
我想你不能但是有没有办法将方法作为属性的参数引用?就像下面的东西?我可以回退使用字符串,但更喜欢使用编译时间来验证类型是否正确.
[LinkToAction(Something)]
public void SomethingElse()
{
}
public static void Something()
{
}
public class LinkToActionAttribute : Attribute
{
public LinkToActionAttribute(MethodInfo info)
{
}
}
Run Code Online (Sandbox Code Playgroud)
抱歉,但你不能。这些可以作为属性的参数传递:
这个问题与您的问题类似:Is it possible to have a delegate as attribute argument? 。那里有一个对您有用的解决方法。