Click to See Complete Forum and Search --> : c# function call from a string


zingmatter
05-07-2007, 10:12 AM
I'd like to be able to store function names in a database (the functions containing specific code that needs to be run on data in that record).

For example, a record contains a field: "functions" and for that record it contains: "myFunction1" (as a string). Is there a way of getting this and then running a function of the same name (other than just doing a switch statement).

Currently doing something like:

switch (strFunctionIn) {
case "myFunction1":
int someValue = myFunction1();
etc...

Any ideas? I reckon it can't be done but my C# isn't all that great so I may be missing something.

Thanks

Ribeyed
05-07-2007, 12:25 PM
Hi,
you can add a handler dynamically to your code, is that what you want?

sareeshps
09-13-2007, 10:33 AM
You can use .Net Reflection to achive this i.e you will be able to call the function stored in a variable using reflection