Skip to content

Commit

Permalink
Adding overload for custom constructors to take the context; closes A…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Dec 17, 2011
1 parent e6ec194 commit f648512
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/AutoMapper/IMappingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ IMappingExpression<TSource, TDestination> Include<TOtherSource, TOtherDestinatio
IMappingExpression<TSource, TDestination> AfterMap(Action<TSource, TDestination> afterFunction);
IMappingExpression<TSource, TDestination> AfterMap<TMappingAction>() where TMappingAction : IMappingAction<TSource, TDestination>;
IMappingExpression<TSource, TDestination> ConstructUsing(Func<TSource, TDestination> ctor);
IMappingExpression<TSource, TDestination> ConstructUsing(Func<ResolutionContext, TDestination> ctor);
void As<T>();
IMappingExpression<TSource, TDestination> MaxDepth(int depth);
IMappingExpression<TSource, TDestination> ConstructUsingServiceLocator();
Expand Down
7 changes: 6 additions & 1 deletion src/AutoMapper/Internal/MappingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ public IMappingExpression<TSource, TDestination> AfterMap<TMappingAction>() wher

public IMappingExpression<TSource, TDestination> ConstructUsing(Func<TSource, TDestination> ctor)
{
_typeMap.DestinationCtor = src => ctor((TSource)src);
return ConstructUsing(ctxt => ctor((TSource) ctxt.SourceValue));
}

public IMappingExpression<TSource, TDestination> ConstructUsing(Func<ResolutionContext, TDestination> ctor)
{
_typeMap.DestinationCtor = ctxt => ctor(ctxt);

return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/MappingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ object IMappingEngineRunner.CreateObject(ResolutionContext context)

if (typeMap != null)
if (typeMap.DestinationCtor != null)
return typeMap.DestinationCtor(context.SourceValue);
return typeMap.DestinationCtor(context);
else if (typeMap.ConstructDestinationUsingServiceLocator && context.Options.ServiceCtor != null)
return context.Options.ServiceCtor(destinationType);
else if (typeMap.ConstructDestinationUsingServiceLocator)
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/TypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Action<object, object> AfterMap
}
}

public Func<object, object> DestinationCtor { get; set; }
public Func<ResolutionContext, object> DestinationCtor { get; set; }

public List<string> IgnorePropertiesStartingWith { get; set; }

Expand Down

0 comments on commit f648512

Please sign in to comment.