Closed
Description
AddExpressionMapping() not working for Expression with open generic mapping.
Source/destination types
public class ReportS
{
public IList<MenuS<OptionS, Func<OptionS>>> Menu { get; set; }
}
public class ReportT
{
public IList<MenuT<OptionT, Func<OptionT>>> Menu { get; set; }
}
public class MenuT<T, TV>
{
public Expression<TV> LambdaExpression { get; set; }
public T Option { get; set; }
}
public class MenuS<T, TV>
{
public Expression<TV> LambdaExpression { get; set; }
public T Option { get; set; }
}
public class OptionS
{
}
public class OptionT
{
}
Mapping configuration
Mapper.Initialize(
cfg =>
{
cfg.AddExpressionMapping();
cfg.CreateMap<OptionS, OptionT>();
cfg.CreateMap(typeof(MenuS<,>), typeof(MenuT<,>));
cfg.CreateMap<ReportS, ReportT>();
});
Version: x.y.z
Automapper 7.0.1
AutoMapper.Extensions.ExpressionMapping 1.0.3
Expected behavior
Expression should have mapped to target type
Actual behavior
InvalidOperationException: No coercion operator is defined between types 'OptionS' and 'OptionT'.
Steps to reproduce
var source = new ReportS
{
Menu = new List<MenuS<OptionS, Func<OptionS>>>
{
new MenuS<OptionS, Func<OptionS>>
{
Option = new OptionS(), LambdaExpression = () => new OptionS()
}
}
};
var target = Mapper.Map<ReportT>(source);
Metadata
Metadata
Assignees
Labels
No labels