Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResolutionContext passed into Condition always has a null SourceType #204

Closed
danielp37 opened this issue May 10, 2012 · 1 comment
Closed

Comments

@danielp37
Copy link

This was something that worked in Automapper 2.0 that now appears to be broken in Automapper 2.1.

I have the following statement:

    public static IMappingExpression<TSource, TDestination> DontCopyNullValues<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression)
    {
      expression.ForAllMembers(opt => opt.Condition((ResolutionContext r) => r.SourceValue != null));
      return expression;
    }

I use it to not have null values copied from the source object to the destination object. In these cases the source object already exists and I am copying values over to the destination object. It looks like in changeset f5daca4 a change was made to call propertyMap.ShouldAssignValue sooner. Previously the call to ShouldAssignValue looked like this:

           var newContext = context.CreateMemberContext(typeMap, result.Value, destinationValue, targetSourceType,
                                  propertyMap);

           if (!propertyMap.ShouldAssignValue(newContext))
              return;

but now it looks like:

if (!propertyMap.ShouldAssignValue(context.CreateMemberContext(null, null, null, null, propertyMap)))
     return;

I can work around this by calling the following:

r.PropertyMap.ResolveValue(r.Parent).Value != null

but this seems to be working around something that should just work.

@lock
Copy link

lock bot commented May 8, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants