Executing a method or function using a String

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I have a situation in which the name of a method is stored in a String, and
I want to know if Visual Basic.NET has any way for me to execute that method
by passing the String to some existing method. Any help would be
appreciated. Thanks.
 
A

Armin Zingler

Nathan said:
I have a situation in which the name of a method is stored in a String, and
I want to know if Visual Basic.NET has any way for me to execute that method
by passing the String to some existing method. Any help would be
appreciated. Thanks.


Where do you get the method name from? (IMO) Only if it's not stored
inside the application it makes sense to use Reflection. See:
CallByName, System.Type.InvokeMember, System.Reflection.MethodBase.Invoke


Armin
 
M

Martin Honnen

Nathan said:
I have a situation in which the name of a method is stored in a String, and
I want to know if Visual Basic.NET has any way for me to execute that method
by passing the String to some existing method. Any help would be
appreciated. Thanks.

Reflection allows that:
http://msdn.microsoft.com/en-us/library/cxz4wk15.aspx

You might however reconsider your approach and check whether using
delegates to store methods itself instead of method names is possible.
 

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