Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@
bool typesAreSameAndImplementCorrectInterface = false;
if (left.Type == right.Type)
{
var interfaces = left.Type.GetInterfaces().Where(x => x.GetTypeInfo().IsGenericType);
var typeToCheck = TypeHelper.GetNonNullableType(left.Type);
var interfaces = typeToCheck.GetInterfaces().Where(x => x.GetTypeInfo().IsGenericType);
if (isEquality)
{
typesAreSameAndImplementCorrectInterface = interfaces.Any(x => x.GetGenericTypeDefinition() == typeof(IEquatable<>));
Expand Down Expand Up @@ -1504,7 +1505,7 @@
{
if (!propertyNames.Add(propName!))
{
throw ParseError(exprPos, Res.DuplicateIdentifier, propName);

Check warning on line 1508 in src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

Possible null reference argument for parameter 'args' in 'Exception ExpressionParser.ParseError(int pos, string format, params object[] args)'.

Check warning on line 1508 in src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

Possible null reference argument for parameter 'args' in 'Exception ExpressionParser.ParseError(int pos, string format, params object[] args)'.

Check warning on line 1508 in src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

Possible null reference argument for parameter 'args' in 'Exception ExpressionParser.ParseError(int pos, string format, params object[] args)'.

Check warning on line 1508 in src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

Possible null reference argument for parameter 'args' in 'Exception ExpressionParser.ParseError(int pos, string format, params object[] args)'.
}

properties.Add(new DynamicProperty(propName!, expr.Type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,59 @@ public void FilterByNullableLocalDate_WithDynamicExpressionParser_CompareWithNul
result.Should().HaveCount(numberOfEntities);
}

private class EntityWithInstant
{
public Instant Timestamp { get; set; }
public Instant? TimestampNullable { get; set; }
}

[Theory]
[InlineData(">", 1)]
[InlineData(">=", 2)]
[InlineData("<", 1)]
[InlineData("<=", 2)]
public void FilterByInstant_WithRelationalOperator(string op, int expectedCount)
{
// Arrange
var now = SystemClock.Instance.GetCurrentInstant();
var data = new List<EntityWithInstant>
{
new EntityWithInstant { Timestamp = now - Duration.FromHours(1) },
new EntityWithInstant { Timestamp = now },
new EntityWithInstant { Timestamp = now + Duration.FromHours(1) }
}.AsQueryable();

// Act
var result = data.Where($"Timestamp {op} @0", now).ToList();

// Assert
result.Should().HaveCount(expectedCount);
}

[Theory]
[InlineData(">", 1)]
[InlineData(">=", 2)]
[InlineData("<", 1)]
[InlineData("<=", 2)]
public void FilterByNullableInstant_WithRelationalOperator(string op, int expectedCount)
{
// Arrange
var now = SystemClock.Instance.GetCurrentInstant();
var data = new List<EntityWithInstant>
{
new EntityWithInstant { TimestampNullable = now - Duration.FromHours(1) },
new EntityWithInstant { TimestampNullable = now },
new EntityWithInstant { TimestampNullable = now + Duration.FromHours(1) },
new EntityWithInstant { TimestampNullable = null }
}.AsQueryable();

// Act
var result = data.Where($"TimestampNullable {op} @0", now).ToList();

// Assert - null values are excluded from comparison results
result.Should().HaveCount(expectedCount);
}

public class LocalDateConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string);
Expand Down
Loading