Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private bool ShouldConvertMemberExpression(Type initialType, Type mappedType)
initialType = Nullable.GetUnderlyingType(initialType);

if (mappedType.IsNullableType())
initialType = Nullable.GetUnderlyingType(mappedType);
mappedType = Nullable.GetUnderlyingType(mappedType);

return mappedType == Enum.GetUnderlyingType(initialType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ protected override MapperConfiguration Configuration
.ReverseMap();
config.CreateMap<Entity<int>, EntityDto<SimpleEnumInt>>()
.ForMember(dest => dest.Value, config => config.MapFrom(src => src.Value))
.ReverseMap();
config.CreateMap<Entity<int?>, EntityDto<SimpleEnumInt>>()
.ForMember(dest => dest.Value, config => config.MapFrom(src => src.Value))
.ReverseMap();
config.CreateMap<Entity<uint>, EntityDto<SimpleEnumUInt>>()
.ForMember(dest => dest.Value, config => config.MapFrom(src => src.Value))
Expand Down Expand Up @@ -198,6 +201,29 @@ public void BinaryExpressionEquals<TEnum, TNumeric>(TEnum enumConstant, TNumeric
Assert.Equal(result, correctResult);
}

[Fact]
public void BinaryExpressionEqualsWithNullable()
{
SimpleEnumInt enumConstant = SimpleEnumInt.Value2;
int? numericConstant = 2;
Expression<Func<Entity<int?>, bool>> mappedExpression;
{
var param = Expression.Parameter(typeof(EntityDto<SimpleEnumInt>), "x");
var property = Expression.Property(param, nameof(EntityDto<SimpleEnumInt>.Value));
var constantExp = Expression.Constant(enumConstant, typeof(SimpleEnumInt));
var binaryExpression = Expression.Equal(property, constantExp);
var lambdaExpression = Expression.Lambda(binaryExpression, param);
mappedExpression = Mapper.Map<Expression<Func<Entity<int?>, bool>>>(lambdaExpression);
}

var mappedExpressionDelegate = mappedExpression.Compile();

var entity = new Entity<int?> { Value = numericConstant };
var result = mappedExpressionDelegate(entity);

Assert.True(result);
}

private class ComplexEntity
{
public int intToEnum { get; set; }
Expand Down