Options for invoking methods dynamically in C#

525 Views Asked by At

I've seen quite a few questions related to how do I invoke a method like this and that. What I haven't found is a listing of the different options of how to invoke a method via reflection or any other means in csharp.

Can someone explain in detail the different ways of dynamically invoking a method in csharp? From reflection to emitting IL and any other ways in between. I would like to know of all the different ways from most expensive to least expensive in terms of resources.

1

There are 1 best solutions below

2
On BEST ANSWER

To get you started, here are the ways to invoke a method in .NET that I can think of:

  • Call
  • Callvirt
  • Delegate
  • DynamicMethod
  • MethodInfo.Invoke
  • Type.InvokeMember
  • TypeDescriptor
  • Reflection.Emit
  • Expression Trees

I remember some article comparing the speed of most of them, but I can't seem to find it at the moment.

A quick Google search came up with these links: [Link] [Link] [Link] [Link] [Link]