Skip to content

Commit a044177

Browse files
committed
Equality operators now work for non-constants as well
1 parent 2136e75 commit a044177

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1920,10 +1920,10 @@ void CheckAndPromoteOperands(Type signatures, TokenId opId, string opName, ref E
19201920

19211921
if (nativeOperation != null)
19221922
{
1923-
if (left is ConstantExpression)
1923+
// first try left operand's equality operators
1924+
found = _methodFinder.ContainsMethod(left.Type, nativeOperation, true, args);
1925+
if (!found)
19241926
found = _methodFinder.ContainsMethod(right.Type, nativeOperation, true, args);
1925-
else if (right is ConstantExpression)
1926-
found = _methodFinder.ContainsMethod(left.Type, nativeOperation, true, args);
19271927
}
19281928

19291929
if (!found && !_methodFinder.ContainsMethod(signatures, "F", false, args))

test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs

+37
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,43 @@ public void ExpressionTests_Type_StructWithIntegerEquality()
17151715
Assert.Equal(resultValuesL.ToArray(), resultIn);
17161716
}
17171717

1718+
[Fact]
1719+
public void ExpressionTests_Type_StructWithIntegerEquality_BothVariablesInStruct()
1720+
{
1721+
// Arrange
1722+
var valuesL = new[]
1723+
{
1724+
new
1725+
{
1726+
Id = new SnowflakeId(1L),
1727+
Var = 1
1728+
},
1729+
new
1730+
{
1731+
Id = new SnowflakeId(2L),
1732+
Var = 1
1733+
},
1734+
new
1735+
{
1736+
Id = new SnowflakeId(1L),
1737+
Var = 2
1738+
}
1739+
}.AsQueryable();
1740+
1741+
var resultValuesL = new[] {
1742+
new {
1743+
Id = new SnowflakeId(1L),
1744+
Var = 1
1745+
}
1746+
}.AsQueryable();
1747+
1748+
// Act
1749+
var resultL = valuesL.Where("it.Id == it.Var");
1750+
1751+
// Assert
1752+
Assert.Equal(resultValuesL.ToArray(), resultL);
1753+
}
1754+
17181755
[Fact]
17191756
public void ExpressionTests_Type_Integer_Qualifiers_Negative()
17201757
{

0 commit comments

Comments
 (0)