Skip to content
Permalink
Browse files

#89: Fix mapping Nullable enum to int?

  • Loading branch information...
cezarypiatek committed Sep 6, 2019
1 parent 8112db2 commit 34b2efe144245e5b3e4ba3df2f9fb7a5f9aeac53
@@ -35,6 +35,8 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public AuthenticationKind Authentication { get; set;}
public string SecondAuthentication { get; set;}
public AuthenticationKind ThirdAuthentication { get; set;}
public int? FourthAuthentication { get; set;}
public AuthenticationKind? FifthAuthentication { get; set;}
}

public class UserSourceDTO
@@ -96,6 +98,8 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public AuthenticationKind Authentication { get; set;}
public AuthenticationKind SecondAuthentication { get; set;}
public string ThirdAuthentication { get; set;}
public AuthenticationKind? FourthAuthentication { get; set;}
public int? FifthAuthentication { get; set;}
}

public class AddressEntity
@@ -46,7 +46,9 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
Birthday = entity.Birthday,
Authentication = entity.Authentication,
SecondAuthentication = entity.SecondAuthentication.ToString(),
ThirdAuthentication = Enum.Parse(typeof(AuthenticationKind), entity.ThirdAuthentication, true)
ThirdAuthentication = Enum.Parse(typeof(AuthenticationKind), entity.ThirdAuthentication, true),
FourthAuthentication = (int?)entity.FourthAuthentication,
FifthAuthentication = (AuthenticationKind?)entity.FifthAuthentication
};
}
}
@@ -73,6 +75,8 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public AuthenticationKind Authentication { get; set;}
public string SecondAuthentication { get; set;}
public AuthenticationKind ThirdAuthentication { get; set;}
public int? FourthAuthentication { get; set;}
public AuthenticationKind? FifthAuthentication { get; set;}
}

public class UserSourceDTO
@@ -134,6 +138,8 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public AuthenticationKind Authentication { get; set;}
public AuthenticationKind SecondAuthentication { get; set;}
public string ThirdAuthentication { get; set;}
public AuthenticationKind? FourthAuthentication { get; set;}
public int? FifthAuthentication { get; set;}
}

public class AddressEntity
@@ -212,7 +212,7 @@ private static SyntaxNode CreateAccessPropertyExpression(SyntaxNode globalTarget

private bool IsUnwrappingNeeded(ITypeSymbol targetType, MappingElement element)
{
return targetType.Equals(element.ExpressionType) == false && ObjectHelper.IsSimpleType(targetType);
return targetType.Equals(element.ExpressionType) == false && (ObjectHelper.IsSimpleType(targetType) || SymbolHelper.IsNullable(targetType, out _));
}

private MappingElement TryToUnwrap(ITypeSymbol targetType, MappingElement element)
@@ -163,9 +163,4 @@ public static IAssemblySymbol FindContextAssembly(this SemanticModel semanticMod
return symbol.ContainingAssembly;
}
}

struct SampleStruct
{
public int Test { get; set; }
}
}

0 comments on commit 34b2efe

Please sign in to comment.
You can’t perform that action at this time.