开发者

c# dynamic proxy

How determine in C# if an Object is the original 开发者_如何学运维object or a dynamic proxy of the original object?

I run into this need playing with nhibernate.


Answer is here in a previous question.

You can detect if a class is a NHibernate proxy by casting it to (unsurprisingly) INHibernateProxy.

If you need to get the underlying "real" object, use:

Session.GetSessionImplementation().PersistenceContext.Unproxy(proxiedObject) You don't need to test for proxies to call Unproxy; it returns the original parameter if it's not a proxy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜