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 Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.0.13</VersionPrefix>
<VersionPrefix>1.0.14</VersionPrefix>
</PropertyGroup>

<Choose>
Expand Down
2 changes: 1 addition & 1 deletion GitHubReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes

GitHubReleaseNotes.exe . --output CHANGELOG.md --skip-empty-releases --language en --version 1.0.13.0
GitHubReleaseNotes.exe . --output CHANGELOG.md --skip-empty-releases --language en --version 1.0.14.0
4 changes: 2 additions & 2 deletions src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ Expression GenerateConditional(Expression test, Expression expr1, Expression exp
// - convert expr2 to nullable
if (Constants.IsNull(expr1) && expr2.Type.GetTypeInfo().IsValueType)
{
Type nullableType = typeof(Nullable<>).MakeGenericType(expr2.Type);
Type nullableType = TypeHelper.ToNullableType(expr2.Type);
expr1 = Expression.Constant(null, nullableType);
expr2 = Expression.Convert(expr2, nullableType);
}
Expand All @@ -1187,7 +1187,7 @@ Expression GenerateConditional(Expression test, Expression expr1, Expression exp
// - convert expr1 to nullable
if (Constants.IsNull(expr2) && expr1.Type.GetTypeInfo().IsValueType)
{
Type nullableType = typeof(Nullable<>).MakeGenericType(expr1.Type);
Type nullableType = TypeHelper.ToNullableType(expr1.Type);
expr2 = Expression.Constant(null, nullableType);
expr1 = Expression.Convert(expr1, nullableType);
}
Expand Down
7 changes: 7 additions & 0 deletions src/System.Linq.Dynamic.Core/Parser/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ public static bool IsNullableType(Type type)
return type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
}

public static Type ToNullableType(Type type)
{
Check.NotNull(type, nameof(type));

return IsNullableType(type) ? type : typeof(Nullable<>).MakeGenericType(type);
}

public static bool IsSignedIntegralType(Type type)
{
return GetNumericTypeKind(type) == 2;
Expand Down
36 changes: 34 additions & 2 deletions test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,39 @@ public void ExpressionTests_NullCoalescing()
}

[Fact]
public void ExpressionTests_NullPropagating_Null()
public void ExpressionTests_NullPropagating_DateTime_Value()
{
// Arrange
var q = new[] {
new { id = 1, date1 = (DateTime?) DateTime.Now, date2 = DateTime.Now.AddDays(-1)}
}.AsQueryable();

// Act
var result = q.OrderBy(x => x.date2).Select(x => x.id).ToArray();
var resultDynamic = q.OrderBy("np(date2)").Select("id").ToDynamicArray<int>();

// Assert
Check.That(resultDynamic).ContainsExactly(result);
}

[Fact]
public void ExpressionTests_NullPropagating_NullableDateTime()
{
// Arrange
var q = new[] {
new { id = 1, date1 = (DateTime?) DateTime.Now, date2 = DateTime.Now.AddDays(-1)}
}.AsQueryable();

// Act
var result = q.OrderBy(x => x.date1).Select(x => x.id).ToArray();
var resultDynamic = q.OrderBy("np(date1)").Select("id").ToDynamicArray<int>();

// Assert
Check.That(resultDynamic).ContainsExactly(result);
}

[Fact]
public void ExpressionTests_NullPropagating_Integer_Null()
{
// Arrange
var testModels = User.GenerateSampleModels(2, true).ToList();
Expand All @@ -1306,7 +1338,7 @@ public void ExpressionTests_NullPropagating_Null()
}

[Fact]
public void ExpressionTests_NullPropagating_Value()
public void ExpressionTests_NullPropagating_Integer_Value()
{
// Arrange
var testModels = User.GenerateSampleModels(2, true).ToList();
Expand Down