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.0
VERSION: 10.0.1
NUGET_HOST: https://api.nuget.org/v3/index.json
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
jobs:
Expand Down
6 changes: 3 additions & 3 deletions .tests/Tests.DynamicExpression/Tests.DynamicExpression.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="4.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="4.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions DynamicExpression/DynamicExpression.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<TargetFrameworks>net10.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PlatformTarget>AnyCPU</PlatformTarget>
<Version>10.0.0.0</Version>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<FileVersion>10.0.0.0</FileVersion>
<Version>10.0.0.0</Version>
<LangVersion>latest</LangVersion>
<Authors>Michael Vivet</Authors>
<Product>Dynamic Expression</Product>
Expand All @@ -15,7 +15,8 @@
<PackageTags>Lampda, Expression, Linq, Dynamic, Criteria, Query, Paging, Pagination, Sort, Sorting</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
- Upgraded to .NET 10.
- Updated NuGets.
- Added Geometry converter for query model binder.
</PackageReleaseNotes>
<PackageLicense>https://raw.githubusercontent.com/vivet/DynamicExpression/master/LICENSE</PackageLicense>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down Expand Up @@ -47,8 +48,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.200" 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" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions DynamicExpression/ModelBinders/Const/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using DynamicExpression.ModelBinders.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace DynamicExpression.ModelBinders.Const;
Expand All @@ -18,7 +19,8 @@ internal static class Constants
PreserveReferencesHandling = PreserveReferencesHandling.None,
Converters =
{
new StringEnumConverter()
new StringEnumConverter(),
new GeometryConverterIgnoreCase()
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace DynamicExpression.ModelBinders.Converters;

/// <summary>
/// A <see cref="GeometryConverter"/> that ignores case when reading JSON properties for geometries.
/// </summary>
public class GeometryConverterIgnoreCase : GeometryConverter
{
/// <summary>
/// Reads JSON into a <see cref="Geometry"/> object, renaming properties to match expected casing.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object to create.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The <see cref="JsonSerializer"/> used for deserialization.</param>
/// <returns>The deserialized geometry object.</returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="reader"/>, <paramref name="objectType"/>, or <paramref name="serializer"/> is null.</exception>
/// <exception cref="JsonSerializationException">Thrown if the JSON token is not an object.</exception>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
ArgumentNullException.ThrowIfNull(reader);
ArgumentNullException.ThrowIfNull(objectType);
ArgumentNullException.ThrowIfNull(serializer);

var token = JToken.Load(reader);

if (token.Type != JTokenType.Object)
{
throw new JsonSerializationException("Expected object");
}

var obj = (JObject)token;

if (objectType.IsSubclassOf(typeof(Geometry)))
{
RenameProperty(obj, "Type", "type");
RenameProperty(obj, "Coordinates", "coordinates");
RenameProperty(obj, "Geometries", "geometries");
}

var jsonReader = new JTokenReader(obj);

jsonReader
.Read();

return base.ReadJson(jsonReader, objectType, existingValue, serializer);
}


private static void RenameProperty(JObject @object, string from, string to)
{
ArgumentNullException.ThrowIfNull(@object);
ArgumentNullException.ThrowIfNull(from);
ArgumentNullException.ThrowIfNull(to);

if (!@object.TryGetValue(from, StringComparison.OrdinalIgnoreCase, out var value))
{
return;
}

@object
.Remove(from);

@object[to] = value;
}
}
Loading