开发者

c# dynamic proxy

开发者 https://www.devze.com 2022-12-28 20:29 出处:网络
How determine in C# if an Object is the original 开发者_如何学运维object or a dynamic proxy of the original object?

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

精彩评论

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

关注公众号