EventInfo.GetRaiseMethod() always returns null

  • Thread starter Thread starter Sergio Geralnik
  • Start date Start date
S

Sergio Geralnik

I am trying to use this method to get a MethodInfo object
but the method always returns a null.
See my sample code below:

this.button1 = new System.Windows.Forms.Button();
this.button1.Click += new System.EventHandler
(this.button1_Click);

private void button1_Click(object sender, System.EventArgs
e)
{
EventInfo eventInfo = (sender as Button).GetType().GetEvent
("Click");

// This line always results in raiseMethod being null
MethodInfo raiseMethod = eventInfo.GetRaiseMethod();

}

Thanks for any help.
 
Sergio,
I am trying to use this method to get a MethodInfo object
but the method always returns a null.

I don't know which method's MethodInfo you want to retrieve, but
events generated by the C# compiler (or VB.NET) never have a raise
method associated with them (it's optional) so that's why
GetRaiseMethod always will return null for those events.



Mattias
 
Back
Top