开发者

custom condition method attributes in C#

开发者 https://www.devze.com 2023-01-20 06:30 出处:网络
I\'m wondering if I can do something like this in c#: public Custome开发者_开发问答rManagerScreen()

I'm wondering if I can do something like this in c#:

    public Custome开发者_开发问答rManagerScreen() 
    {
        [TestAttirubute("CustomerManagerScreen_Load")]
            private void CustomerManagerScreen_Load(object sender, EventArgs e)
            {
                CustomerLoad();
            }
    }

as you can see, method name is a parameter of TestAttribute, what I want to achieve is CustomerManagerScreen_Load will be discarded depending on the result of the TestAttirubute

this is the attribute class...

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;
        }
    }


Not like that, but with the ConditionalAttribute you can.

One restriction however is that your methods must return void.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号