帮助 将 mixins 从 Castle.DynamicProxy 迁移到 DynamicProxy2
我正在尝试将一些代码从使用 DynamicProxy 更新为 DynamicProxy2。特别是我们使用 DynamicProxy 来提供两个类的混合。设置是这样的:
public interface IHasShape
{
string Shape { get; }
}
public interface IHasColor
{
string Color { get; }
}
public interface IColoredShape : IHasShape, IHasColor
{
}
然后假设 IHasShape 和 IHasColor 的一些明显的具体实现,我们将创建一个像这样的 mixin:
public IColoredShape CreateColoredShapeMixin(IHasShape shape, IHasColor color)
{
ProxyGenerator gen = new ProxyGenerator();
StandardInterceptor interceptor = new StandardInterceptor();
GeneratorContext context = new GeneratorContext();
context.AddMiniInstance(color);
return gen.CreateCustomProxy(typeof(IColoredShape), intercetor, shape, context);
}
除了作为代理创建的结果之外,没有 IColoredShape 的具体实现。 StandardInterceptor 接受对 IColoredShape 对象的调用,并根据需要将它们委托给“shape”或“color”对象。
但是,我一直在尝试新的 DynamicProxy2,但找不到等效的实现。
I am trying to update some code from using DynamicProxy to DynamicProxy2. In particular we where using DynamicProxy to provide a mixin of two classes. The setup is something like this:
public interface IHasShape
{
string Shape { get; }
}
public interface IHasColor
{
string Color { get; }
}
public interface IColoredShape : IHasShape, IHasColor
{
}
Then assuming some obvious concrete implementations of IHasShape and IHasColor we would create a mixin like this:
public IColoredShape CreateColoredShapeMixin(IHasShape shape, IHasColor color)
{
ProxyGenerator gen = new ProxyGenerator();
StandardInterceptor interceptor = new StandardInterceptor();
GeneratorContext context = new GeneratorContext();
context.AddMiniInstance(color);
return gen.CreateCustomProxy(typeof(IColoredShape), intercetor, shape, context);
}
There are no concrete implementations of IColoredShape except as a result of the proxy creation. The StandardInterceptor takes calls on the IColoredShape object and delegates them to either the 'shape' or 'color' objects as appropriate.
However, I've been playing around with the new DynamicProxy2 and can't find the equivalent implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以如果我理解正确的话,您有两个带有实现的接口,以及另一个实现这两个接口的接口,并且您想在第三个接口下混合这两个接口的实现,对吗?
OK, so if I understand you correctly you have two interfaces with implementations, and another interfaces that implements both of them and you want to mix the implementations of these two interfaces under the 3rd one, correct?