views:

406

answers:

1

Hi,

I can't work out how to get the parameter types for an event.

For instance, I can only see using a MethodInfo to get parameters, but I have either an EventInfo or a FieldInfo.

What I want is to be able to get 'Boolean' from this:

Public Event EventName(ByVal sender As Object, ByVal value As Boolean)

I could theoretically try something like GetRaiseMethod() but that won't work (because that method returns null as per this link) and even if it did it would require a method binding first and this is meant to be for a test suite just confirming that the event has a certain typed parameter at initialisation.

Any ideas?

+3  A: 

You can get the type of the second parameter as follows assuming the event EventName is declared in the class DeclaringClass and the event has at least to parameters. Else you will probably receive an exception.

Type secondEventHandlerParameterType = 
   typeof(DeclaringClass).
   GetEvent("EventName").
   EventHandlerType.
   GetMethod("Invoke").
   GetParameters()[1].
   ParameterType;
Daniel Brückner