I'm creating automated gui tester. That's why i have to load assembly dynamically and find out all all ui objects and their events. Last problem I have is to find out what method for example button1 calls on click event. Please ask more details if you need...
The simple (but frustrating) answer is that there's no way of doing this in general. An event doesn't have to simply store the subscribed delegates in a single field - they could be stored in a hashtable, for instance. I believe most of the built-in controls
For simple events defined in your own classes, you could try getting a field with the same name as the event, and get the invocation list for that. That won't help you if someone's using custom add/remove though.
These are not suitable for my purposes. Those expect that you have to write tester class, I'm creating Automated tester which generates tester class by using UI. That's the reason why I have to get dynamically method name.
How to extract event method name!
Olivier Robin
Try this,
using
System.Diagnostics;StackFrame sf=
new StackFrame(true);string
methodName=sf.GetMethod().ToString();I have used this for error handling(logging errors).
Regards,
Nishanth
http://www.nish.somee.com
Timpie
you could simulate the click event by calling the "PerformClick()" method on the button.
You can find a good review on techniques for UI test automation in the following articles:
http://msdn.microsoft.com/msdnmag/issues/05/01/TestRun/ (for a reflection-based approach)
http://msdn.microsoft.com/msdnmag/issues/05/09/TestRun/ (for a low-level UI automation)
However the first article assumes that you know the name of the event handling method that is triggered by the Click event.
Hope this helps,
Andres.
Dhanasu
Can you provide more information about what you are trying to do
Andres.
SHELMAN
It' would be ok, but I have to get via reflection etc, Outside of that form.
I get button as Object then I should extract a method as string.
Kent Chenery
I'm creating automated gui tester. That's why i have to load assembly dynamically and find out all all ui objects and their events. Last problem I have is to find out what method for example button1 calls on click event. Please ask more details if you need...
Thank's
Niko
Amit Tzafrir
For simple events defined in your own classes, you could try getting a field with the same name as the event, and get the invocation list for that. That won't help you if someone's using custom add/remove though.
Jon
Pat 34847
NickNotYet
U can get the event information using the EventInfo object of Reflection namespace. but u need to specify the event that u r looking for.
Hope this will help you.
BindingFlags bindflag = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type typebindflag = typeof(System.Windows.Forms.Button);
EventInfo eventinfo = typebindflag.GetEvent("Click", bindflag);
if (eventinfo != null)
{
Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.");
Console.WriteLine(eventinfo.ToString());
}
else
Console.WriteLine("The Click event is not available with the Button class.");
Thanks,
Kedar
KCtin
--Niko
orac123456789
SUPAXE
EventHandler
myDelegate = new System.EventHandler(this.button1_Click);this.button1.Click += myDelegate;
string method = myDelegate.GetInvocationList()[0].Method.Name;
Andres.