George George

George George

  • NA
  • 778
  • 0

using reflection to invoke a method

Sep 7 2008 10:19 PM

Hello everyone,


There are two ways to use reflection to invoke a method,

1. Using InvokeMember;
2. Using GetType.GetMethod to retrieve a MethodInfo object, then use the MethodInfo object to invoke the method.

My point is from the result point of view, they are the same, but method 2 if more efficient if we want to invoke the method multiple of times by the same MethodInfo object -- since each time we call InvokeMember, it needs to find the method, nothing saved as MethodInfo object in method 2 and each time InvokeMember did the binding to find the same method.

My question is whether my point of understanding is correct and whether there any more differences/pros/cons compared with the 2 methods.


thanks in advance,
George


Answers (2)