I need to call a method on an object but I do not know the method name until runtime.
What are the techniques available?
(e.g. GetMethod().Invoke(), delegates, c# 4.0 dynamic)
Thanks!
The C# 4.0 dynamic
functionality is going to be the easiest way to do this. In a very real sense, dynamic
is "just a wrapper" around Reflection. It's a very good wrapper, though, that is probably your best option.
Other ways, in approximately increasing level of difficult:
The last three are not for the faint of heart. Your best bet is to use dynamic
or write your own Reflection code. If I had had dynamic
three years ago when I was writing code for something similar, I would have used it.