C# : Is there a generic way to forward a method call to another object (with the same interface)?

标签 c# reflection

有没有办法以通用方式实现此模式?

一个调度器对象和一堆工作对象都派生自同一个接口(interface)。

任何对调度程序对象的方法调用都需要被调度(转发)到其中一个工作对象(带有所有参数)。

每个方法都需要发现自己的名称,在工作对象中找到相应的方法,发现参数,然后进行调用。如果可能,不使用可变参数机制。

有什么办法吗?反射?代码生成?

最佳答案

它可能不是特别简单,但它非常可靠 - 看看 CaSTLe.DynamicProxy:http://kozmic.pl/dynamic-proxy-tutorial/

关于C# : Is there a generic way to forward a method call to another object (with the same interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4028119/

相关文章:

c# - 从外部应用程序向 Web 浏览器添加书签

使用反射 $foo->$bar() 时性能中断

c# - 如何将 PropertyInfo[] 转换为 Dictionary<string,string>?

c# - 将 lambda 表达式作为参数传递给方法?

c# - 查找文件的更改

c# - Monitor.Pulse/Wait 的异步版本

java - 运行 JUnit @Test 方法的子集

java - 将对象转换为数组

c# - PropertyInfo 中的属性与 CustomAttributes

c# - Asp.Net Core 2.1 ApiController 不会自动验证单元测试下的模型