views:

14

answers:

1

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

    public CustomerManagerScreen() 
    {
        [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;
        }
    }
A: 

Not like that, but with the ConditionalAttribute you can.

One restriction however is that your methods must return void.

leppie