我需要调用以下方法:
public bool Push(button RemoteButtons)
RemoteButtons是这样定义的:
enum RemoteButtons { Play, Pause, Stop }
Push方法属于RemoteControl类。RemoteControl类和RemoteButton枚举都位于一个需要在运行时加载的程序集中。我可以通过以下方式加载程序集并创建RemoteControl实例:
Assembly asm = Assembly.LoadFrom(dllPath);
Type remoteControlType = asm.GetType("RemoteControl");
object remote = Activator.CreateInstance(remoteControlType);
现在,我该如何调用Push方法,因为它唯一的参数是一个枚举类型,我也需要在运行时加载它?
如果我使用C# 4,我会使用dynamic对象,但我使用的是C# 3/.NET 3.5,所以它不可用。
enum RemoteButtons { Play, Pause, Stop }
如果我的理解正确,OP需要明确表达。 :) - IAbstractIRemoteControl
,它公开了bool Push(...)
并由通过反射实例化的类引用并由RemoteControl
实现。这样,您就不必通过反射调用该方法。 - IAbstract