Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public bool TryGenerateAndAlsoNotNullExpression(Expression sourceExpression, boo
{
var expressions = CollectExpressions(addSelf, sourceExpression);

if (expressions.Count == 1 && !(expressions[0] is MethodCallExpression))
if (expressions.Count == 1 && expressions[0] is not MethodCallExpression)
{
generatedExpression = sourceExpression;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ public void Parse_When_PrioritizePropertyOrFieldOverTheType_IsTrue(string expres
CustomTypeProvider = _dynamicTypeProviderMock.Object,
AllowEqualsAndToStringMethodsOnObject = true
};
ParameterExpression[] parameters = [ParameterExpressionHelper.CreateParameterExpression(typeof(Company), "company")
];
ParameterExpression[] parameters = [ ParameterExpressionHelper.CreateParameterExpression(typeof(Company), "company") ];
var sut = new ExpressionParser(parameters, expression, null, config);

// Act
Expand Down
52 changes: 52 additions & 0 deletions test/System.Linq.Dynamic.Core.Tests/QueryableTests.Where.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,58 @@ public void Where_Dynamic_CompareObjectToInt_ConvertObjectToSupportComparisonIsF
act.Should().Throw<InvalidOperationException>().And.Message.Should().MatchRegex("The binary operator .* is not defined for the types");
}

[Fact]
public void Where_Dynamic_NullPropagation_Test1_On_NullableDoubleToString_When_AllowEqualsAndToStringMethodsOnObject_True()
{
// Arrange
var config = new ParsingConfig
{
AllowEqualsAndToStringMethodsOnObject = true
};
var queryable = new[]
{
new { id = "1", d = (double?) null },
new { id = "2", d = (double?) 5 },
new { id = "3", d = (double?) 50 },
new { id = "4", d = (double?) 40 }
}.AsQueryable();

// Act
var result = queryable
.Where(config, """np(it.d, 0).ToString().StartsWith("5", StringComparison.OrdinalIgnoreCase)""")
.Select<double?>("d")
.ToArray();

// Assert
result.Should().ContainInOrder(5, 50);
}

[Fact]
public void Where_Dynamic_NullPropagation_Test2_On_NullableDoubleToString_When_AllowEqualsAndToStringMethodsOnObject_True()
{
// Arrange
var config = new ParsingConfig
{
AllowEqualsAndToStringMethodsOnObject = true
};
var queryable = new[]
{
new { id = "1", d = (double?) null },
new { id = "2", d = (double?) 5 },
new { id = "3", d = (double?) 50 },
new { id = "4", d = (double?) 40 }
}.AsQueryable();

// Act
var result = queryable
.Where(config, """np(it.d.ToString(), "").StartsWith("5", StringComparison.OrdinalIgnoreCase)""")
.Select<double?>("d")
.ToArray();

// Assert
result.Should().ContainInOrder(5, 50);
}

[ExcludeFromCodeCoverage]
private class PersonWithObject
{
Expand Down
Loading