Well..
I want something that i can write once, and use in every form, in every
control.
I have already implementedIExtenderProvider to set the security values in
design time for every control in any forms that i load. Then, what i do,
is go to the database, fetch the security values for that user, store them
in a IPrincipal object that i created and everytime i load a form, i
compare the security values of the user with those in every control. That
works perfect!. I created a method in a base form, all my forms inherits
from it. So, when i load a form, i call that method, pass the parameters
that i need and voila... my controls appear enabled, disabled, visible...
depends on the criteria. So, one piece of code, 5 lines, just works for
every form and every control.
I wanted then, due to the ActionSecurityLevel, to be able to change in
runtime the method to be called when you click on a button. right? 'Cause
i don't wanna be writing code everytime i create a subscription to an
event. I know how to add in runtime an eventHandler to a control... as
easy as Control.[event]+=new System.EventHandler [or any other
handler](the_method_to_call). That's fine. But doesn't prevent the code to
perform any other method that had a subscription to that event.
So, i know also that you can programmatically unsubscribe an event by
Control.[event]-=.......... the problem is that when i am iterating thru
controls, i don't have the way to pass or know which handler[method] is
dealing with the subscription. I could do some trick. Like... once i hace
the control (in my iteration security checking code) i can find its
instance name, ok? lets say button1. ok. then i can ASSUME that when i
created that subscription it took by default the _Click suffix... so, it
would be button1_Click.
Next step would be to cast to Handler this string "button1_Click". So, i
would have to create a Method, returning a handler after i pass a
parameter type string with the "name" i "guess" it's going to have the
handler. does it makes sense?
let's put some pseudo code.
let's assume all controls are button.
foreach(Control c in form.Controls)
if(c.ActionSecurityLevel > User.ActionSecurityLevel)
c.click+=new system.EventHandler(myNonActionCode); --> we have here
added a new handler
c.click-=new system.EventHandler(????????); --> i can't write a
handler manually since you are iterating. i don't know the handler method
since i don't "know" its list of handlers. we can't access list of
suscription from the form to that control event.
MY "SILLY" SOLUTION
in that line of code (???????).. well i would set a method in there that
would return the eventhandler.
private EventHandler getEventHandler(string assumedName) -> remember,
assumed name is the concatenation of instance name of the control and
"_Click"
so, this method supposedly will return a handler with the name by default
that VS gives to a subscription to a click event. for example, for button
instance button1, would be button1_Click.
i know it sounds crazy but i think that funcionality would be great since
i don't have to worry about every button click event handler. if you can
use the button, go to its default handler. you can't? perform my code.
DON"T TELL ME DISABLE IT... cause what i want is to do "things" if that
happens.