Method Address from MethodInfo: How do I get it?

P

pamelafluente

Hi,

I am doing something like the following. MyDelegate is some delegate
function I have defined and SomeMethodInfo is a function of type
MyDelegate


dim MethodToCall as MyDelegate

SomeMethodInfo = Me.SomeClassInstance.GetType.GetMethod("SomeMethod")

MethodToCall = SomeMethodInfo ?? how do I assign the address of the
method ?


I do not know how to make MethodToCall to point to the method.
Ideally I want : MethodToCall = addressOf SomeMethodInfo.Method

How can I do that ?

-P
 
P

pamelafluente

Thanks Mattias,

the delegate is already defined. What I need is to get the method from
the method info:

Public Delegate Function SomeDelegate()

dim MethodToCall as SomeDelegate

'I need something like
MethodToCall = SomeMethodInfo.Method ????

where SomeMethodInfo.Method is a method of type SomeDelegate (I do not
know how to get it)

System.Delegate.CreateDelegate seems to create a delegate, or perhaps I
am missing the hint ...

-P

MethodToCall = SomeMethodInfo.Method ??

Mattias Sjögren ha scritto:
 
M

Mattias Sjögren

'I need something like
MethodToCall = SomeMethodInfo.Method ????

MethodToCall =
DirectCast([Delegate].CreateDelegate(GetType(SomeDelegate),
Me.SomeClassInstance, "SomeMethod"), SomeDelegate)

or if SomeMethod happens to be a Shared method

MethodToCall =
DirectCast([Delegate].CreateDelegate(GetType(SomeDelegate),
SomeMethodInfo), SomeDelegate)


Mattias
 
P

pamelafluente

Thanks Mattias

*Very* helpful. I was missing this useful class !!

-P

Mattias Sjögren ha scritto:
'I need something like
MethodToCall = SomeMethodInfo.Method ????

MethodToCall =
DirectCast([Delegate].CreateDelegate(GetType(SomeDelegate),
Me.SomeClassInstance, "SomeMethod"), SomeDelegate)

or if SomeMethod happens to be a Shared method

MethodToCall =
DirectCast([Delegate].CreateDelegate(GetType(SomeDelegate),
SomeMethodInfo), SomeDelegate)


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top