Well, actually you do not need "someMethodName" in quotation marks. You just do it (full list of programs):
class Program { static void Main(string[] args) { dynamic obj = new SomeObject(); obj.someMethodName("hello"); } } public class SomeObject { public void someMethodName(string message) { Console.WriteLine(message); } }
If your method name comes from some kind of evil place like javascript or something else, you can do this:
class Program { static void Main(string[] args) { dynamic obj = new SomeObject(); var meth = obj.GetType().GetMethod("someMethodName"); meth.Invoke(obj, new object[1]{"hello"}); } } public class SomeObject { public void someMethodName(string message) { Console.WriteLine(message); } }
source share