Skip to content

Commit 1aed80b

Browse files
authored
Merge pull request #85 from jogibear9988/master
Fix Guid? == null comparison
2 parents 1dd9f0a + 8a72624 commit 1aed80b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,9 @@ void CheckAndPromoteOperands(Type signatures, string opName, ref Expression left
18261826

18271827
MethodBase method;
18281828
if (FindMethod(signatures, "F", false, args, out method) != 1)
1829-
throw IncompatibleOperandsError(opName, left, right, errorPos);
1829+
{
1830+
throw IncompatibleOperandsError(opName, left, right, errorPos);
1831+
}
18301832

18311833
left = args[0];
18321834
right = args[1];
@@ -1969,6 +1971,11 @@ int FindBestMethod(IEnumerable<MethodBase> methods, Expression[] args, out Metho
19691971
{
19701972
applicable = applicable.Where(m => applicable.All(n => m == n || IsBetterThan(args, m, n))).ToArray();
19711973
}
1974+
1975+
if (args.Length == 2 && applicable.Length > 1 && (args[0].Type == typeof(Guid?) || args[1].Type == typeof(Guid?)))
1976+
{
1977+
applicable = applicable.Take(1).ToArray();
1978+
}
19721979

19731980
if (applicable.Length == 1)
19741981
{

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,20 @@ public void Operator_Multiplication_Single_Float_Cast()
2828
//Assert
2929
Assert.Equal(6.0m, result);
3030
}
31+
public class TestGuidNullClass
32+
{
33+
public Guid? GuidNull { get; set; }
34+
}
35+
36+
[Fact]
37+
public void GuidNull_Null_Equals_Test()
38+
{
39+
//Arrange
40+
var models = new TestGuidNullClass[] { new TestGuidNullClass() { } }.AsQueryable();
41+
42+
//Act
43+
var result1 = models.Where("it.GuidNull == null");
44+
var result2 = models.Where("null == it.GuidNull");
45+
}
3146
}
32-
}
47+
}

0 commit comments

Comments
 (0)