Dynamic discovery of delegates

  • Thread starter Thread starter Nate
  • Start date Start date
N

Nate

Help please, I need a genius!!!

[I'm using VB.NET 2003]

I have an application that loads assemblies at runtime. These assemblies
have many classes (objects) and some do have several delegates. I want to be
able to discover a delegate on an object, and to be able to programmatically
assign it to a callback address.

In my app, I have an object with delegate defined as follows:

public delegate StringChanged(strNewValue as string)
private myStringChangedDelegate as StringChanged

I then have a method to assign a callback to this delegate, such as:

public sub AddListenerToStringChanged(callback as StringChanged)
myStringChangedDelegate = .... ' you know the drill here...
end sub


The thing is, I can (at runtime) detect the above procedure, but I want I
want to do is to programmatically assign a callback address to this...
something along the lines of:

myObject.AddListenerToStringChanged(addressof obj2.StringChangedListener)


I am guessing that I need to use some kind of "MethodInvoke" or something?
but it's the "Addressof" operator that gets me... I just can't find the
information or the syntax that the compiler will accept.

In summary, my question is:
How do I invoke a method which requires an Addressof operator?

Any help would be truly appreciated. Thanks.
 
If you want to dynamically create a delegate of a type that's unknown
at compile time, use System.Delegate.CreateDelegate().



Mattias
 
Back
Top