Methods C中的自定义条件方法属性
我想知道我是否可以在c中执行类似的操作:Methods C中的自定义条件方法属性,methods,c#-4.0,custom-attributes,Methods,C# 4.0,Custom Attributes,我想知道我是否可以在c中执行类似的操作: public CustomerManagerScreen() { [TestAttirubute("CustomerManagerScreen_Load")] private void CustomerManagerScreen_Load(object sender, EventArgs e) { CustomerLoad();
public CustomerManagerScreen()
{
[TestAttirubute("CustomerManagerScreen_Load")]
private void CustomerManagerScreen_Load(object sender, EventArgs e)
{
CustomerLoad();
}
}
正如您所看到的,方法名称是TestAttribute的一个参数,我想要实现的是CustomerManager Screen_加载将根据TestAttribute的结果被丢弃
这是属性类
public class TestAttirubute: System.Attribute
{
private string _MethodName = string.Empty;
public TestAttirubute(string MethodName)
{
this._MethodName = MethodName;
}
public bool hasPermission()
{
return (SessionManager.CurrentUser.UserRole.Role.Rights.Where(a => a.Resource.Code == this._MethodName).Count() != 0) ? true: false;
}
}
不是那样的,但只要你有条件就可以了
但是,一个限制是,您的方法必须返回void。不确定您要问什么;似乎与asp.net授权相关,但您一般会这样问。还有,返回真的吗?对:错。