Hi there, System.Reflection.Type::InvokeMember() performs the method dispatch resolution for you, _each time you invoke the method_, whereas that resolution only happens when you look up the MethodInfo via System.Type::GetMethod(...)
Hence, if you find yourself not just doing one-shot invocations, but repeatedly invoking the same method via reflection, opting for the MethodInfo route makes better sense (from a perf POV.) hth --sigbjorn ----- Original Message ----- From: "Fahad" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, July 28, 2002 06:56 Subject: [ADVANCED-DOTNET] MethodInfo.Invoke versus Type.InvokeMethod > Just a couple of inquiries about the reflection API of .NET. Interestingly, > the Type class has exposed a very "versatile" method called InvokeMethod... > you can use BindingsFlag to specify if you'd like to invoke an object's > method or get/set properties or even get/set fields. What my question is, > _WHEN_ really to use InvokeMethod from the Type class and _WHEN_ to use > MethodInfo from the Reflection namespace? You could definitely invoke a > method using a MethodInfo obect, but then again, you can do the same using > the Type object's InVokeMethod, is there an efficiency loss in either of > the two (except for the fact that you'll be instantiating a new object for > using MethodInfo while you don't have to when using InvokeMethod). I > believe MethodInfo should be applied to situations where you're more > interested in finding out passive information of the method rather than > calling "Invoke" only. Is that correct? Would Type.InvokeMethod qualify > for 'invoking methods reflectively'? And so, would it be wise using > InvokeMethod for setting/getting feilds and properties? Also note that I am > talking about objects that have been instantiated the traditional way > (using 'new') and not reflectively.... > > Another question.. when talking about "finding method signatures" > and "matching them" and then "invoking" the correct method... does that > imply going through each and every Parameter (using ParameterInfo) and so > on and then explicitly matching each string, or can be plain trust > the "delegatory" nature of the InvokeMethod command that looks for the > correct BindingFlag and then calls on the method... could someone please > elaborate? Thank you :) > > You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.