Home All Groups Group Topic Archive Search About

Method Address from MethodInfo: How do I get it?

Author
17 Sep 2006 4:14 PM
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

Author
17 Sep 2006 6:48 PM
Mattias Sjögren
>How can I do that ?

System.Delegate.CreateDelegate


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
17 Sep 2006 8:26 PM
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:

Show quoteHide quote
> >How can I do that ?
>
> System.Delegate.CreateDelegate
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
Author
18 Sep 2006 7:16 PM
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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
18 Sep 2006 9:46 PM
pamelafluente
Thanks Mattias

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

-P

Mattias Sjögren ha scritto:

Show quoteHide quote
> > '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
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.