Permalink
Browse files

Adding overload for custom constructors to take the context; closes #151

  • Loading branch information...
1 parent e6ec194 commit f6485124bc5759042bcd924c72486bd31b1c99be @jbogard jbogard committed Dec 17, 2011
@@ -28,6 +28,7 @@ public interface IMappingExpression<TSource, TDestination>
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();
@@ -380,7 +380,12 @@ public void ConvertUsing(ITypeConverter<TSource, TDestination> converter)
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;
}
@@ -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)
@@ -71,7 +71,7 @@ public Type DestinationType
}
}
- public Func<object, object> DestinationCtor { get; set; }
+ public Func<ResolutionContext, object> DestinationCtor { get; set; }
public List<string> IgnorePropertiesStartingWith { get; set; }

0 comments on commit f648512

Please sign in to comment.