|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Method Address from MethodInfo: How do I get it?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 >How can I do that ? System.Delegate.CreateDelegateMattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. 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. > 'I need something like MethodToCall => MethodToCall = SomeMethodInfo.Method ???? 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. 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.
Sorting Arraylist Of Objects
System Idle Process force cast of object to mytype... How to ensure DB changes complete? CreateToolhelp32Snapshot mouse freezes in Visual Studio Pop up dialog after Main Form displayed Can't access controls programmatically when inside FormView control (newbie -VB 2005 EE) TextBox question MenuItem vs. ToolStripMenuItem |
|||||||||||||||||||||||