473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Method Address from MethodInfo: How do I get it?

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

Sep 17 '06 #1
4 3019
>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.
Sep 17 '06 #2

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:
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.
Sep 17 '06 #3
'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.
Sep 18 '06 #4

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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
3
by: Clinton Pierce | last post by:
I can create a delegate like this, and everything works fine: class Foo { private delegate void NextPanel(); private NextPanel myself; // And later in a method private void EffStart() {
1
by: Ajay Pal Singh | last post by:
Hi, I am making an windows service similar to windows task schedular. The service would invoke the methods of some assemblies at some predefined schedules. (windows service read the...
7
by: Gaetan | last post by:
I would like to extend the capabilities of my application by calling a user method residing in a client provided assembly without having to recompile my application. Things would work like this:...
9
by: Joel Finkel | last post by:
Is there a way to execute a method if all we know is its name as a string? Let's say we have the following class. What is the code for the Execute method? I need a solution that works with the...
8
by: Gaetan | last post by:
Is is possible in C# to have the equivalent of an array of function pointers in C? I have a situation where a top level class exposes methods like Add, Delete, ... and a few child classes with...
10
by: schneider | last post by:
I'm looking for a way to programaticly call a method from a different object and associate the two objects at runtime. Example: Object A exist and is unknow, I want object B to be able to call a...
2
by: D2 | last post by:
Hi, I have a requirement where I need to call a generic method without knowing the class name i.e. I'm getting class name from xml file. Given below is a replica of the scenario we are having. ...
3
by: Anders Borum | last post by:
Hi I need to invoke a generic method determined at runtime. The method has two arguments, a string and a generic type that is constrained to a struct: public void Add<T>(string key, T value)...
0
by: =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?= | last post by:
"Anders Borum" wrote: Hi Anders, I'm afraid the GetMethod() does not currently support filtering on generic parameters so you will have to loop through the existing methods using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.