views:

209

answers:

1
+2  Q: 

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.

+3  A: 

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.

Serapth