相关疑难解决方法(0)

Castle DynamicProxy:获取未经过代理的对象

我正在使用Castle DynamicProxy为我的类型添加一个拦截器.现在我需要获得底层基本类型(而不是代理本身).

我在SO上找到了一些提示,建议使用ProxyUtil类,如下所示:

object realInstance = ProxyUtil.GetUnproxiedInstance(proxyInstance);
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用

bool isProxy = ProxyUtil.IsProxy(realInstance);
Run Code Online (Sandbox Code Playgroud)

总是如此.

我还尝试使用以下代码片段,这基本上是ProxyUtil正在做的事情:

var accessor = proxyInstance as IProxyTargetAccessor;
var realInstance = accessor.DynProxyGetTarget();
Run Code Online (Sandbox Code Playgroud)

同样的结果,realInstance仍然是一个代理.

我在这里错过了什么?

.net castle-dynamicproxy

6
推荐指数
3
解决办法
4389
查看次数

标签 统计

.net ×1

castle-dynamicproxy ×1