You can do an Assembly.Load (in System.Reflection). There are about 6 or 7 overloads available, some only need the assembly name, others can load from a COFF image.
What if I don't want to use assembly? I mean if the caller is in the same program as the function to be called.
For example, there is a function called F1() in the same class as the function Main(). What I want do is to let Main() get a function name ("F1" from the standard input and invoke the function.
I would like to attach my code here to share with other C# dudes.
//Assume we have a function Test() to call by name.
string FunctionName="Test";
Type t=this.GetType();
MethodInfo mi=t.GetMethod(FunctionName);
if (mi!=null)
mi.Invoke(this, null);
else
MessageBox.Show("Wrong Function Name"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.