Ok. So I use this ->
Code:
MethodInfo method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).FirstOrDefault(mi => mi.Name == name);
Then it will return null if such a method doesnt exist.
To invoke the method I use
Code:
method.Invoke(null, null);
It would be great if you could post a link about more info about this object type.
(MethodInfo)
I'll try to decode it myself here, and please correct me if I'm wrong.
-typeof(Program)
This probably means that I'm looking for a method inside my program?
-GetMethods()
This searches through the methods in the program according to the paramteres.
-BindingFlags
These specify for what types of methods I search for. Do they have to be static though?
Code:
FirstOrDefault(mi => mi.Name == name)
this probably gets the first method in the list (or first overload) that maches the name the user put in...
Now a few questions =D
1. Can I use non-static and Public methods for this?
2. How would I reference a method from another class?
3. Is it possible to pass arguments? for example
Code:
Method2(string output)
{
Console.WriteLine(output);
}
and call it with
Code:
input: Method2("Read me!")
?