我正在使用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