C# .NET - In a .net Exception how to get parameters for events like button_click

Asked By mohan kumar on 03-Jul-12 03:57 PM
Hi,
I am using this code for getting the parameters of method during exception
System.Diagnostics.StackTrace callStack = new System.Diagnostics.StackTrace();
System.Diagnostics.StackFrame frame = null;
System.Reflection.MethodBase calledMethod = null;
System.Reflection.ParameterInfo [] passedParams = null;
for (int x = 0; x < callStack.FrameCount; x++)
{
    frame
= callStack.GetFrame(x);
    calledMethod
= frame.GetMethod();
    passedParams
= calledMethod.GetParameters();
   
foreach (System.Reflection.ParameterInfo param in passedParams)
       
System.Console.WriteLine(param.ToString());
}
I need parameters for events like button_click (sender e , args) during exception. Give solution for this
Robbe Morris replied to mohan kumar on 03-Jul-12 05:41 PM
Are you really using these values?  sender is an "object" in most event handlers and System.EventArgs for args.  Most well designed code wouldn't use these.  The Click event could call code that exists in a resuable method and not code that exists in an event handler.
mohan kumar replied to Robbe Morris on 04-Jul-12 04:05 PM
hi ,

      How to get the parameter value of method programatically. I need parameter of method before exception.

for example 
public void test(int a, int b)
{
// I need value of a,b programatically
}

test(1,2)

please give solution.