views:

136

answers:

2

This is pretty much a duplicate question but instead of using Castle Dynamic Proxy I'm using LinFu http://stackoverflow.com/questions/1415675/getting-underlying-type-of-a-proxy-object

I'm using automapper to create proxies of interfaces that I'm sending to my viewmodel in Asp.net MVC. My problem is from what I can tell that MVC's default MetadataProvider find the properties and metadata by calling .GetType() on the model.

So what happens is EditorFor() and DisplayFor() templates don't generate any fields. What I need to do is find the proxy target type and then generate my templates. I know I can just parse the name and use GetType( "thename" ) but was wondering if there was an easy way.

A: 

get latest AutoMapper - it uses Castle Dynamic Proxy, and you already know how to get this from there :)

Krzysztof Koźmic
Uh, no: http://code.google.com/p/automapperhome/source/browse/#svn/trunk/lib/LinFu.DynamicProxy
jfar
You're right - apparently only in Silverlight they use Castle : http://www.lostechies.com/blogs/jimmy_bogard/archive/2010/02/18/automapper-for-silverlight-3-0-alpha.aspx which is odd
Krzysztof Koźmic
ok, well - actually I'm right - they **do** use Castle in trunk: http://github.com/jbogard/AutoMapper/tree/master/lib/
Krzysztof Koźmic
no, I think thats jbogards personal clone?, RTW from http://www.codeplex.com/AutoMapper is still using LinFu, just confirmed with code
jfar
+1  A: 

LinFu.DynamicProxy doesn't directly expose the underlying object of a proxy. It simply redirects each method call to an IInterceptor implementation instance. In order to access the underlying object, you'll have to figure out whether or not the current interceptor instance actually has a target class instance, or not.

If you're working with AutoMapper, AFAIK, they use LinFu.DynamicObject to do a lot of the duck taping, and calling GetType() on a dynamic type generated by LinFu.DynamicObject won't even get you the actual type in your domain model--it will just get you an object that has been literally duck-taped together by LinFu itself.

plaureano