Calling a method using a string value?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Does anyone know if its possible to call a method from it's string reproesentation e.g

int CallFN(string FunctionName

return ... FunctionName..


So if a method exists called GetAge which returns the number 1
I want to call this by calling
CallFn("GetAge")

T.I.A
 
jacew said:
Does anyone know if its possible to call a method from it's string reproesentation e.g.

int CallFN(string FunctionName)
{
return ... FunctionName...
}

So if a method exists called GetAge which returns the number 12
I want to call this by calling
CallFn("GetAge");

You need to use reflection. Have a look at Type.GetMethod to find out
how to get the method, and then the Invoke method on the returned
MethodInfo to run it. A reflection tutorial on the net will no doubt
give more information.
 
Back
Top