Simon
Simon

Reputation: 34840

How do i get the the full name of the proxyed type for a nhibernate DynamicProxy?

I am using a netdatacontractserializer and a SerializationBinder to create my own runtime types for nhibernate proxies on the client side.

This all works except I am forced to assume that there is only one type by each name in the domain model. i.e. i am forced to ignore the namespace. The reason is that SerializationBinder only gives me access to "MyObjectProxyb04bae2d04d34e8a98b1d93bf24428cc" and "DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" to derive the parent tyep.

As you can see there is no data that points to the namespace of the parent type.

I have had a look at changing the name of the generated proxy (to include a namespace prefix) but that seems to be hard coded.

Upvotes: 0

Views: 303

Answers (1)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99730

You can cast the proxy to INHibernateProxy and get the persistent underlying class:

((INHibernateProxy)proxy).HibernateLazyInitializer.PersistentClass

Upvotes: 2

Related Questions