我正在使用Castle DynamicProxy向我的类型添加拦截器。 现在我需要获取底层基础类型(不是代理本身)。Castle DynamicProxy:获取未加密的对象
我发现这么几个暗示,建议使用ProxyUtil类是这样的:
object realInstance = ProxyUtil.GetUnproxiedInstance(proxyInstance);
这似乎并不工作,因为
bool isProxy = ProxyUtil.IsProxy(realInstance);
总是正确的。
我也使用下面的代码段,这基本上是什么ProxyUtil正在做尝试:
var accessor = proxyInstance as IProxyTargetAccessor;
var realInstance = accessor.DynProxyGetTarget();
具有相同的结果,realInstance仍然是一个代理。
我在这里错过了什么?
我使用'CreateClassProxyWithTarget(实例,拦截器)'来创建代理。 问题是NHibernate失败,因为它认为它应该映射代理,而不是目标。 –
cguedel