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 .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- master
env:
APP_NAME: DynamicExpression
VERSION: 10.0.3
VERSION: 10.0.4
NUGET_HOST: https://api.nuget.org/v3/index.json
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
jobs:
Expand Down
14 changes: 14 additions & 0 deletions .tests/Tests.DynamicExpression/CriteriaBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,20 @@ public void BuildWhenIntersectsTest()
Assert.AreEqual("((x.Location != null) AndAlso x.Location.Intersects(POINT (0 0)))", expression.Body.ToString());
}

[TestMethod]
public void BuildWhenIntersectsAndPropertyTypeMismatchTest()
{
var criteriaExpression = new CriteriaExpression();

criteriaExpression.Intersects(nameof(Customer.Name), new Point(0, 0));

var exception = Assert.ThrowsExactly<ArgumentException>(() => CriteriaBuilder.Build<Customer>(criteriaExpression));

Assert.IsInstanceOfType<ArgumentException>(exception.InnerException);
StringAssert.Contains(exception.Message, nameof(Customer.Name));
StringAssert.Contains(exception.Message, nameof(OperationType.Intersects));
}

[TestMethod]
public void BuildWhenWithinTest()
{
Expand Down
12 changes: 12 additions & 0 deletions DynamicExpression/CriteriaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ private static Expression GetExpression(Expression parameter, Criteria criteria,
}
}

try
{
return CriteriaBuilder.GetExpressionCore(member, value, value2, operationType);
}
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException && ex is not ArgumentOutOfRangeException)
{
throw new ArgumentException($"Criteria for property '{name}' cannot be applied: operation '{operationType}' with value type '{value.Type.Name}' is not compatible with the property's type '{member.Type.Name}'.", ex);
}
}

private static Expression GetExpressionCore(Expression member, Expression value, Expression value2, OperationType operationType)
{
if (value.Type.IsEnum)
{
var expression = Expression.Convert(member, Enum.GetUnderlyingType(value.Type));
Expand Down
3 changes: 2 additions & 1 deletion DynamicExpression/DynamicExpression.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageTags>Lampda, Expression, Linq, Dynamic, Criteria, Query, Paging, Pagination, Sort, Sorting</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
- Improved exception handling for property type mismatch.
- Updated NuGets
</PackageReleaseNotes>
<PackageLicense>https://raw.githubusercontent.com/vivet/DynamicExpression/master/LICENSE</PackageLicense>
Expand Down Expand Up @@ -47,7 +48,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.301" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.400" PrivateAssets="All" />
<PackageReference Include="NetTopologySuite" Version="2.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="4.0.0" />
Expand Down
Loading