Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
#168: Handle conversions between simple types wrapped in nullable lik…
Browse files Browse the repository at this point in the history
…e decimal? -> double
  • Loading branch information
cezarypiatek committed Mar 13, 2021
1 parent e8b5122 commit df1259e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public string? MiddleName { get; set; }
public string LastName { get; set; }
public int AgeValue { get; set; }
public double Weight { get; set; }
public AccountDTO? Account { get; set; }
public AccountDTO Account2 { get; set; }
public List<AccountDTO>? Debs { get; set; }
Expand Down Expand Up @@ -96,6 +97,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public string LastName { get; set; }
public string? MiddleName { get; set; }
public int? Age { get; set; }
public decimal? Weight { get; set; }
public AccountEntity? Account { get; set; }
public AccountEntity? Account2 { get; set; }
public List<AccountEntity>? Debs { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
MiddleName = entity.MiddleName,
LastName = entity.LastName,
AgeValue = entity.Age ?? throw new ArgumentNullException(nameof(entity), "The value of 'entity.Age' should not be null"),
Weight = (double)(entity.Weight ?? throw new ArgumentNullException(nameof(entity), "The value of 'entity.Weight' should not be null")),
Account = entity.Account != null ? new AccountDTO
{
BankName = entity.Account.BankName,
Expand Down Expand Up @@ -74,6 +75,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public string? MiddleName { get; set; }
public string LastName { get; set; }
public int AgeValue { get; set; }
public double Weight { get; set; }
public AccountDTO? Account { get; set; }
public AccountDTO Account2 { get; set; }
public List<AccountDTO>? Debs { get; set; }
Expand Down Expand Up @@ -142,6 +144,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public string LastName { get; set; }
public string? MiddleName { get; set; }
public int? Age { get; set; }
public decimal? Weight { get; set; }
public AccountEntity? Account { get; set; }
public AccountEntity? Account2 { get; set; }
public List<AccountEntity>? Debs { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ public async Task<MappingElement> MapExpression(MappingElement source, Annotated
}


if (ObjectHelper.IsSimpleType(targetType.Type) && SymbolHelper.IsNullable(sourceType.Type, out var underlyingType) )
if (ObjectHelper.IsSimpleType(targetType.Type) && SymbolHelper.IsNullable(sourceType.Type, out var underlyingType))
{
return new MappingElement
var mapping = new MappingElement
{
Expression = OrFailWhenArgumentNull(source.Expression),
Expression = OrFailWhenArgumentNull(source.Expression),
ExpressionType = new AnnotatedType(underlyingType, false)
};

return IsConversionToSimpleTypeNeeded(targetType.Type, underlyingType) ? ConvertToSimpleType(targetType, mapping, mappingContext) : mapping;
}

if (IsConversionToSimpleTypeNeeded(targetType.Type, source.ExpressionType.Type))
Expand Down

0 comments on commit df1259e

Please sign in to comment.