Skip to content

Commit 6213fd1

Browse files
author
Oleg Nadymov
committed
Fix for parsing Guid and string in the same condition
1 parent e13c9d1 commit 6213fd1

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/System.Linq.Dynamic.Core/Parser/SupportedOperands/IEqualitySignatures.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ internal interface IEqualitySignatures : IRelationalSignatures
1313

1414
void F(Guid x, Guid y);
1515
void F(Guid? x, Guid? y);
16-
void F(Guid x, string y);
17-
void F(Guid? x, string y);
18-
void F(string x, Guid y);
19-
void F(string x, Guid? y);
16+
17+
// Disabled 2 lines below according to unit test ParseLambda_With_If_Guid_Null
18+
//void F(Guid x, string y);
19+
//void F(Guid? x, string y);
20+
21+
// Disabled 2 lines below according to unit test ParseLambda_With_If_Null_Guid
22+
//void F(string x, Guid y);
23+
//void F(string x, Guid? y);
2024
}
2125
}

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

+36
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace System.Linq.Dynamic.Core.Tests
1111
{
1212
public class DynamicExpressionParserTests
1313
{
14+
15+
1416
private class MyClass
1517
{
1618
public int Foo()
@@ -452,5 +454,39 @@ public void ParseLambda_With_InnerStringLiteral()
452454
object result = del.DynamicInvoke(String.Empty);
453455
Check.That(result).IsEqualTo(originalTrueValue);
454456
}
457+
458+
[Fact]
459+
public void ParseLambda_With_If_Guid_Null()
460+
{
461+
var objContext = new User();
462+
var guidEmpty = Guid.Empty;
463+
var someId = Guid.NewGuid();
464+
var expressionText = $"iif(@0.{nameof(objContext.Id)} == null, @0.{nameof(objContext.Id)} == Guid.Parse(\"{someId}\"), {nameof(objContext.Id)}={nameof(objContext.Id)})";
465+
466+
var lambda = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(typeof(User), null, expressionText, objContext);
467+
var boolLambda = lambda as Expression<Func<User, bool>>;
468+
Check.That(boolLambda).IsNotEqualTo(null);
469+
470+
var del = lambda.Compile();
471+
object result = del.DynamicInvoke(objContext);
472+
Check.That(result).IsEqualTo(true);
473+
}
474+
475+
[Fact]
476+
public void ParseLambda_With_If_Null_Guid()
477+
{
478+
var objContext = new User();
479+
var guidEmpty = Guid.Empty;
480+
var someId = Guid.NewGuid();
481+
var expressionText = $"iif(null == @0.{nameof(objContext.Id)}, @0.{nameof(objContext.Id)} == Guid.Parse(\"{someId}\"), {nameof(objContext.Id)}={nameof(objContext.Id)})";
482+
483+
var lambda = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(typeof(User), null, expressionText, objContext);
484+
var boolLambda = lambda as Expression<Func<User, bool>>;
485+
Check.That(boolLambda).IsNotEqualTo(null);
486+
487+
var del = lambda.Compile();
488+
object result = del.DynamicInvoke(objContext);
489+
Check.That(result).IsEqualTo(true);
490+
}
455491
}
456492
}

0 commit comments

Comments
 (0)