Executing a method or function using a String

  • Thread starter Thread starter Nathan Sokalski
  • Start date 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.
 
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
 
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.
 
Back
Top