动态代理集合接口
我偶尔会编写集合类适配器,即为实现 IListIList
接口有很多方法/属性,我想知道直通代理方法是否可以动态实现?我查看了DynamicObject
,但只能找到一些代理 DTO 类的简单示例,即代理仅具有属性的类。
IList
可以代理吗?
例如
public class ListProxy : IList<T>
{
private IList<T> _adaptee;
public ListProxy(IList<T> adaptee)
{
_adaptee = adaptee
}
// dynamically implement straight-through IList methods / properties
}
I have occasionally had cause to write collection class adapters, i.e. create an adapter for a class that implements IList<T>
proxying its methods, whist adding some extra functionality. The IList
interface has numerous methods / properties, I was wondering whether the straight-through proxy methods could be implemented dynamically? I had a look at DynamicObject
, but could only find a few simple examples that proxy DTO classes, i.e. proxying a class that just has properties.
Is the proxying of IList<T>
possible?
e.g.
public class ListProxy : IList<T>
{
private IList<T> _adaptee;
public ListProxy(IList<T> adaptee)
{
_adaptee = adaptee
}
// dynamically implement straight-through IList methods / properties
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西吗?
Something like this?