如何使用反射调用接口中的方法
我有一个类,该类“class1”正在实现一个接口interface1,
我需要使用反射调用该类中的方法。
我不能按原样使用类名和接口名称,因为这两个名称都会动态更改。`
interface1 objClass = (interface1 )FacadeAdapterFactory.GetGeneralInstance("Class"+ version);
请参阅上面的内容代码片段。类名和接口名应根据其版本而变化。我已经通过使用创建了类的实例
Activator.CreateInstance(Type.GetType("Class1"))
,但我无法为接口创建相同的实例
是否有任何方法可以实现上述上下文。
I have a class and that class 'class1' is implementing an interface interface1
I need to invoke a method in the class using the reflection.
I can't use the class name and interface name as it is because both the name will change dynamically.`
interface1 objClass = (interface1 )FacadeAdapterFactory.GetGeneralInstance("Class"+ version);
See the above code snippet. The class name and the interface name should change according to its version. I have created the instance for class by using
Activator.CreateInstance(Type.GetType("Class1"))
but i m not able to crete the same for interface
Is there any way to implement the above context.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法创建接口的实例,只能创建实现接口的类。
有一些方法可以从接口中提取方法(信息)。
我希望这足够了。
You can't create instance of interface, just class that implements interface.
There are some ways to extract method (info) from interface.
I hope it's sufficient.