1

This is pretty much a duplicate question but instead of using Castle Dynamic Proxy I'm using LinFu 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.

Community
  • 1
  • 1
John Farrell
  • 24,673
  • 10
  • 77
  • 110

2 Answers2

1

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
  • 3,139
  • 6
  • 30
  • 29
  • The best method I've found to retrieve data from a Proxy is to make the proxy implement a known private interface, and then intercept access to that interface and return the values you need. – Jerome Haltom Feb 08 '13 at 21:57
-2

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

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • Uh, no: http://code.google.com/p/automapperhome/source/browse/#svn/trunk/lib/LinFu.DynamicProxy – John Farrell Feb 22 '10 at 13:25
  • 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 Kozmic Feb 22 '10 at 13:41
  • ok, well - actually I'm right - they **do** use Castle in trunk: http://github.com/jbogard/AutoMapper/tree/master/lib/ – Krzysztof Kozmic Feb 22 '10 at 13:46
  • no, I think thats jbogards personal clone?, RTW from http://www.codeplex.com/AutoMapper is still using LinFu, just confirmed with code – John Farrell Feb 22 '10 at 14:32