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

查看:148
本文介绍了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天全站免登陆