I know in php you are able to make a call like:
$function_name = 'hello';
$function_name();
function hello() { echo 'hello'; }
Is this possible in .Net?
I know in php you are able to make a call like:
$function_name = 'hello';
$function_name();
function hello() { echo 'hello'; }
Is this possible in .Net?
In C#, you can create delegates as function pointers. Check out the following MSDN article for information on usage: http://msdn.microsoft.com/en-us/library/ms173171(VS.80).aspx
Yes. You can use reflection. Something like this:
In Fact I am working on Windows Workflow 4.5 and I got to find a way to pass a delegate from a statemachine to a method with no success. The only way I got to find was to pass a string with the name of the method I wanted to pass as delegate and to convert the string to a delegate inside the method. Very nice answer. Thanks. Check this link https://msdn.microsoft.com/en-us/library/53cz7sc6(v=vs.110).aspx
A slight tangent -- if you want to parse and evaluate an entire expression string which contains (nested!) functions, consider NCalc (http://ncalc.codeplex.com/ and nuget)
Ex. slightly modified from the project documentation:
And within the
EvaluateFunction
delegate you would call your existing function.You can invoke methods of a class instance using reflection, doing a dynamic method invocation:
Suppose that you have a method called hello in a the actual instance (this):