问个关于Attribute的问题
我定义了一个Attribute类:
[AttributeUsage(AttributeTargets.All)]
public class BlueryAttribute : Attribute
{
private string privilege;
public BlueryAttribute(string str)
{
this.privilege = str;
}
public string Privilege
{
get
{
return this.privilege;
}
}
}
在页面代码的类和方法使用:
[BlueryAttribute("A")]
public partial class AttributeTest : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
[BlueryAttribute("B")]
protected void Button1_Click(object sender, EventArgs e)
{
}
}
其中,PageBase是页面的基类,我需要在里面的某事件(不一定是OnLoad)完成以下工作:如果是回发,则可以获取到标识在方法上特性字符串(“B”)
PageBase类如下:
public class PageBase : System.Web.UI.Page
{
public PageBase() { }
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
BlueryAttribute attribute = (BlueryAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(BlueryAttribute));
}
}
我的问题:不知道如何获取相应方法上的特性,请指教,谢谢~