Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mrahhal committed Feb 2, 2024
1 parent b781320 commit 5a1d85f
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ protected static BinaryExpression MakeComparisonExpression<T>(
}
else
{
// We call EnsureAdditionalConversions only when generating comparisons as these conversions
// are unneeded when generating an equality (Expression.Equal).
return compare(
EnsureAdditionalConversions(memberAccess),
EnsureAdditionalConversions(EnsureMatchingType(memberAccess, referenceValue)));
Expand All @@ -99,11 +101,11 @@ protected static BinaryExpression MakeComparisonExpression<T>(

private static Expression EnsureAdditionalConversions(Expression expression)
{
// For enums, we need to convert to the underlying type for comparisons to work.
if (expression.Type.IsEnum)
{
var enumUnderlyingType = Enum.GetUnderlyingType(expression.Type);

return Expression.Convert(expression, enumUnderlyingType);
var underlyingType = Enum.GetUnderlyingType(expression.Type);
return Expression.Convert(expression, underlyingType);
}

return expression;
Expand Down

0 comments on commit 5a1d85f

Please sign in to comment.