C#如何生成在运行时动态实现不同的接口的对象? [英] C# How to generate an object implementing different interfaces dynamically at runtime?

查看:192
本文介绍了C#如何生成在运行时动态实现不同的接口的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找如何解决一个问题,我甚至不知道这有可能在所有的C#&放大器; .NET 3.5

I'm looking at how to solve a problem and I'm not even sure this might be possible at all in C# & .NET 3.5:

说我有接口数量有限,每个描述一个具体的,非相关的一套方法。现在,我有每个可以实现只是这些接口的一个子集的一些真实世界的设备。

Say I have a limited number of interfaces, each describing a specific, non-related set of methods. Now I have a number real-world devices which each may implement just a subset of these interfaces.

在通讯科与这些设备的建立,他们会告诉我哪些功能他们有。我现在想创建实现接口(设备每类似一个能力)的对象,这样在我的应用程序架构上涨我能:

During set-up of comms with these devices they will tell me which capabilities they have. I would now like to create an object implementing the interfaces (each resembling one capability of the device) so that higher up in my application architecture I'm able to:


  • 对上述接口编写代码

  • 测试,如果生成对象实现某个接口,看看某些行动的支持

我不知道在所有的方法来对这个问题的使用。任何意见或接近最欢迎!

I'm not sure at all which approach to use towards this problem. Any comments or approaches most welcome!

推荐答案

尝试类似的 LinFu.DynamicObject

这篇关于C#如何生成在运行时动态实现不同的接口的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆