Open Generic mappings #549

Closed
wants to merge 3 commits into
from

2 participants

@TylerCarlson1

Addresses Issue #59

Changed layout to class structure and put generics at the end of the list.
Once found it will cache the map into the type mapping and the other find mappings will find it next time.

@jbogard jbogard commented on the diff Jul 8, 2014
src/AutoMapper/Internal/DelegateFactory.cs
@@ -49,6 +49,12 @@ public LateBoundPropertyGet CreateGet(PropertyInfo property)
{
ParameterExpression instanceParameter = Expression.Parameter(typeof(object), "target");
+ if (property.DeclaringType.IsGenericType)
@jbogard
AutoMapper member
jbogard added a line comment Jul 8, 2014

Can this be modified to use expression trees? Bare reflection is pretty slow by orders of magnitude.

@TylerCarlson1
TylerCarlson1 added a line comment Jul 8, 2014

I think so, I wrote it a while back, before I understood how to use expression trees from project to, so I believe it can.
Also this wasn't written with speed in mind because the request was so old.

@TylerCarlson1
TylerCarlson1 added a line comment Nov 21, 2014

I looked at this again and I can't seem to do pure expression trees without making the property not generic. What I can do is change it to get Type of object and create/cache expression trees of a property with that type. So IDelegateFactory instead of LateBoundPropertyGet returned, it will be Func<object, LateBondPropertyGet>. Non generic will just ignore object and return the lambda as normal. GetType will have to be used but once I got the property the first time it should speed up by not having to recreate it.

I don't have it all ready to submit yet, but I know the extra function I can do the caching of the expression, and retrieve it by type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jbogard
AutoMapper member

Like it! One question, what happens when the type parameters differ?

@TylerCarlson1

I didn't account for that. I went off the original request first and see what people thought before going full blown into every possible scenario I can imagine.

I don't really have or can imagine a need right now I just thought it was a interesting problem to solve.

@jbogard
AutoMapper member
@jbogard jbogard added the Feature label Sep 12, 2014
@jbogard jbogard added this to the 3.3.0 milestone Sep 12, 2014
@jbogard jbogard closed this in 81fe659 Nov 21, 2014
@TylerCarlson1 TylerCarlson1 deleted the TylerCarlson1:TryOpenGenerics branch Nov 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment