Skip to content

Commit 8f6026a

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

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
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))

src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Description>This is a .NETStandard / .NET Core port of the the Microsoft assembly for the .Net 4.0 Dynamic language functionality.</Description>
44
<AssemblyTitle>System.Linq.Dynamic.Core</AssemblyTitle>
55
<Authors>Microsoft;Scott Guthrie;King Wilder;Nathan Arnott;Stef Heyenrath</Authors>
6-
<TargetFrameworks>net35;net40;net45;net46;netstandard1.3;netstandard2.0;uap10.0;netcoreapp2.1</TargetFrameworks>
6+
<TargetFrameworks>net35;net40;net45;net46;netstandard1.3;netstandard2.0;netcoreapp2.1</TargetFrameworks>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<AssemblyName>System.Linq.Dynamic.Core</AssemblyName>
99
<AssemblyOriginatorKeyFile>System.Linq.Dynamic.Core.snk</AssemblyOriginatorKeyFile>

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)