Retrieving a handle to a private delegate

  • Thread starter Thread starter Fredrik Strandberg
  • Start date Start date
F

Fredrik Strandberg

Hi!

I have some problems when testing a system.

In class A i have:

Public Event CommEvent As CommEventHandler
Public Delegate Sub CommEventHandler()

and a method:

EnableEvents(ByVal Callback As CommEventHandler)

Then in class B i have

Private Sub OnCommEventReceived() Handles A.CommEvent
From my test class (class C) I need to call EnableEvents with
OnCommEventReceived as an argument. The problem is I do not know how to
provide a handle to OnCommEventReceived. Since OnCommEventReceived is
private I guess I need to use reflection, but I cannot make it work.

I have used for instance MethodInfo to invoke private methods before,
but now I just need some kind of handle to the OnCommEventReceived
method in class B to provide to the EnableEvents method in class A.

Thank you!

/Fredrik Strandberg
 
Fredrik said:
Hi!

I have some problems when testing a system.

In class A i have:

Public Event CommEvent As CommEventHandler
Public Delegate Sub CommEventHandler()

and a method:

EnableEvents(ByVal Callback As CommEventHandler)

Then in class B i have

Private Sub OnCommEventReceived() Handles A.CommEvent

OnCommEventReceived as an argument. The problem is I do not know how to
provide a handle to OnCommEventReceived. Since OnCommEventReceived is
private I guess I need to use reflection, but I cannot make it work.

I have used for instance MethodInfo to invoke private methods before,
but now I just need some kind of handle to the OnCommEventReceived
method in class B to provide to the EnableEvents method in class A.

Since you know how to call B.OnCommEventReceived, how about providing
*in class C* a proxy method that has the same signature, and just calls
B.OnCommEventReceived (via reflection). Then just give C.Proxy to
A.EnableEvents.
 
Back
Top