I'm using Castle DynamicProxy to add an interceptor to my types.
Now I need to get the underlying base type (NOT the proxy itself).
I found a few hints on SO that suggested to use the ProxyUtil class like this:
object realInstance = ProxyUtil.GetUnproxiedInstance(proxyInstance);
This does not seem to work as
bool isProxy = ProxyUtil.IsProxy(realInstance);
is always true.
I also tried using the following code snippet, which is essentially what ProxyUtil is doing:
var accessor = proxyInstance as IProxyTargetAccessor;
var realInstance = accessor.DynProxyGetTarget();
with the same results, realInstance is still a proxy.
What am I missing here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…