在 C# 中动态调用方法的选项

发布于 2024-08-11 05:31:34 字数 163 浏览 1 评论 0原文

我看到了很多与如何调用这样那样的方法相关的问题。我没有找到如何通过反射或 csharp 中的任何其他方式调用方法的不同选项的列表。

有人可以详细解释在 csharp 中动态调用方法的不同方式吗?从反射到发射 IL 以及介于两者之间的任何其他方式。我想知道在资源方面从最昂贵到最便宜的所有不同方式。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

站稳脚跟 2024-08-18 05:31:34

为了帮助您入门,我可以想到以下在 .NET 中调用方法的方法:

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

我记得有一篇文章比较了大多数树的速度,但我现在似乎找不到它。

快速 Google 搜索出现了以下链接: [Link]< /a> [链接] [链接] [链接] [链接]

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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文