From 16c461dfe16196a06d927df893ade00332f1ca08 Mon Sep 17 00:00:00 2001
From: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Date: Sun, 22 Dec 2024 11:28:12 +0100
Subject: [PATCH 1/8] Run tests, examples and benchmarks against .NET 9
---
.github/workflows/build.yml | 3 +++
.github/workflows/codeql.yml | 1 +
Directory.Build.props | 3 +++
benchmarks/Benchmarks.csproj | 2 +-
package-versions.props | 13 +++++++++++++
src/Examples/DapperExample/DapperExample.csproj | 4 ++--
src/Examples/DapperExample/Program.cs | 9 +++++++--
.../DatabasePerTenantExample.csproj | 2 +-
src/Examples/GettingStarted/GettingStarted.csproj | 2 +-
.../JsonApiDotNetCoreExample.csproj | 2 +-
.../MultiDbContextExample.csproj | 2 +-
.../NoEntityFrameworkExample.csproj | 2 +-
src/Examples/ReportsExample/ReportsExample.csproj | 2 +-
test/AnnotationTests/AnnotationTests.csproj | 2 +-
test/DapperTests/DapperTests.csproj | 2 +-
test/DiscoveryTests/DiscoveryTests.csproj | 2 +-
.../JsonApiDotNetCoreTests.csproj | 2 +-
test/MultiDbContextTests/MultiDbContextTests.csproj | 2 +-
.../NoEntityFrameworkTests.csproj | 2 +-
.../SourceGeneratorTests.csproj | 2 +-
test/TestBuildingBlocks/CapturingLoggerProvider.cs | 4 ++++
test/TestBuildingBlocks/TestBuildingBlocks.csproj | 2 +-
test/UnitTests/UnitTests.csproj | 2 +-
23 files changed, 49 insertions(+), 20 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index da0993c185..8a8437e9aa 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -48,6 +48,7 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
+ 9.0.x
- name: Show installed versions
shell: pwsh
run: |
@@ -166,6 +167,7 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
+ 9.0.x
- name: Git checkout
uses: actions/checkout@v4
- name: Restore tools
@@ -221,6 +223,7 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
+ 9.0.x
- name: Git checkout
uses: actions/checkout@v4
with:
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index eb0375769e..5abd2b1dc0 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -29,6 +29,7 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
+ 9.0.x
- name: Git checkout
uses: actions/checkout@v4
- name: Initialize CodeQL
diff --git a/Directory.Build.props b/Directory.Build.props
index dc48433409..4e8f6cd101 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -24,6 +24,9 @@
-->
IDE0028;IDE0300;IDE0301;IDE0302;IDE0303;IDE0304;IDE0305
$(NoWarn);$(UseCollectionExpressionRules)
+
+
+ $(NoWarn);NETSDK1215
diff --git a/benchmarks/Benchmarks.csproj b/benchmarks/Benchmarks.csproj
index 9dbb9ba093..90d53461d2 100644
--- a/benchmarks/Benchmarks.csproj
+++ b/benchmarks/Benchmarks.csproj
@@ -1,7 +1,7 @@
Exe
- net8.0
+ net9.0
true
diff --git a/package-versions.props b/package-versions.props
index ed9b06b1aa..b5d2f30cb3 100644
--- a/package-versions.props
+++ b/package-versions.props
@@ -20,6 +20,17 @@
2.8.*
+
+
+ N/A
+
+
+ 9.0.*
+ 9.0.*
+ 9.0.0-*
+ $(AspNetCoreVersion)
+
+
8.0.0
@@ -27,6 +38,7 @@
8.0.*
8.0.*
+ $(EntityFrameworkCoreVersion)
$(AspNetCoreVersion)
@@ -38,6 +50,7 @@
6.0.*
2.1.*
7.0.*
+ $(EntityFrameworkCoreVersion)
8.0.*
diff --git a/src/Examples/DapperExample/DapperExample.csproj b/src/Examples/DapperExample/DapperExample.csproj
index f49c3e4b40..2d3fad689d 100644
--- a/src/Examples/DapperExample/DapperExample.csproj
+++ b/src/Examples/DapperExample/DapperExample.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
@@ -16,6 +16,6 @@
-
+
diff --git a/src/Examples/DapperExample/Program.cs b/src/Examples/DapperExample/Program.cs
index f7bf198af9..31e5814e5b 100644
--- a/src/Examples/DapperExample/Program.cs
+++ b/src/Examples/DapperExample/Program.cs
@@ -31,8 +31,13 @@
}
case DatabaseProvider.MySql:
{
- builder.Services.AddMySql(connectionString, ServerVersion.AutoDetect(connectionString),
- optionsAction: options => SetDbContextDebugOptions(options));
+#if NET9_0_OR_GREATER
+ ServerVersion serverVersion = await ServerVersion.AutoDetectAsync(connectionString);
+#else
+ ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
+#endif
+
+ builder.Services.AddMySql(connectionString, serverVersion, optionsAction: options => SetDbContextDebugOptions(options));
break;
}
diff --git a/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj b/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj
index 0ccb4bbc5f..a22b938ba0 100644
--- a/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj
+++ b/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/src/Examples/GettingStarted/GettingStarted.csproj b/src/Examples/GettingStarted/GettingStarted.csproj
index 1f4645f323..22fc0529b1 100644
--- a/src/Examples/GettingStarted/GettingStarted.csproj
+++ b/src/Examples/GettingStarted/GettingStarted.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
index 0ccb4bbc5f..a22b938ba0 100644
--- a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
+++ b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj b/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj
index 1f4645f323..22fc0529b1 100644
--- a/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj
+++ b/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj b/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj
index c5b18320f0..c45552dc2d 100644
--- a/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj
+++ b/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/src/Examples/ReportsExample/ReportsExample.csproj b/src/Examples/ReportsExample/ReportsExample.csproj
index bff4909317..3f2c288b23 100644
--- a/src/Examples/ReportsExample/ReportsExample.csproj
+++ b/src/Examples/ReportsExample/ReportsExample.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/AnnotationTests/AnnotationTests.csproj b/test/AnnotationTests/AnnotationTests.csproj
index 081046adb0..7c5e5f3ae0 100644
--- a/test/AnnotationTests/AnnotationTests.csproj
+++ b/test/AnnotationTests/AnnotationTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0;netstandard2.0
+ net9.0;net8.0;net6.0;netstandard2.0
diff --git a/test/DapperTests/DapperTests.csproj b/test/DapperTests/DapperTests.csproj
index 45d9c6a88d..1420e0dd60 100644
--- a/test/DapperTests/DapperTests.csproj
+++ b/test/DapperTests/DapperTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/DiscoveryTests/DiscoveryTests.csproj b/test/DiscoveryTests/DiscoveryTests.csproj
index a64d3be689..295d5340fa 100644
--- a/test/DiscoveryTests/DiscoveryTests.csproj
+++ b/test/DiscoveryTests/DiscoveryTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj b/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
index 38d665aa5b..95a623d0f9 100644
--- a/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
+++ b/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/MultiDbContextTests/MultiDbContextTests.csproj b/test/MultiDbContextTests/MultiDbContextTests.csproj
index 54497bfada..6466d8d75f 100644
--- a/test/MultiDbContextTests/MultiDbContextTests.csproj
+++ b/test/MultiDbContextTests/MultiDbContextTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
index 080666d491..968d798be3 100644
--- a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
+++ b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/SourceGeneratorTests/SourceGeneratorTests.csproj b/test/SourceGeneratorTests/SourceGeneratorTests.csproj
index e28bdc20d1..8b7d42fdca 100644
--- a/test/SourceGeneratorTests/SourceGeneratorTests.csproj
+++ b/test/SourceGeneratorTests/SourceGeneratorTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/TestBuildingBlocks/CapturingLoggerProvider.cs b/test/TestBuildingBlocks/CapturingLoggerProvider.cs
index 3996b1c9e2..38ec60ed3a 100644
--- a/test/TestBuildingBlocks/CapturingLoggerProvider.cs
+++ b/test/TestBuildingBlocks/CapturingLoggerProvider.cs
@@ -10,7 +10,11 @@ public sealed class CapturingLoggerProvider : ILoggerProvider
private static readonly Func DefaultFilter = (_, _) => true;
private readonly Func _filter;
+#if NET9_0_OR_GREATER
+ private readonly Lock _lockObject = new();
+#else
private readonly object _lockObject = new();
+#endif
private readonly List _messages = [];
public CapturingLoggerProvider()
diff --git a/test/TestBuildingBlocks/TestBuildingBlocks.csproj b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
index 40e10eb297..a6f6ff4299 100644
--- a/test/TestBuildingBlocks/TestBuildingBlocks.csproj
+++ b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj
index 99fc7ce781..e977ac0c8c 100644
--- a/test/UnitTests/UnitTests.csproj
+++ b/test/UnitTests/UnitTests.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net9.0;net8.0;net6.0
From 7a89c499c044a2c660ba2f2336de034cf57ab9a4 Mon Sep 17 00:00:00 2001
From: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Date: Sun, 22 Dec 2024 12:14:52 +0100
Subject: [PATCH 2/8] Drop .NET 6
---
.github/workflows/build.yml | 3 -
.github/workflows/codeql.yml | 1 -
Directory.Build.props | 5 -
JsonApiDotNetCore.sln.DotSettings | 1 +
README.md | 8 +-
package-versions.props | 15 +-
.../DapperExample/DapperExample.csproj | 2 +-
src/Examples/DapperExample/Program.cs | 6 +-
.../Repositories/ResultSetMapper.cs | 3 -
.../DatabasePerTenantExample.csproj | 2 +-
.../GettingStarted/GettingStarted.csproj | 2 +-
.../Definitions/TodoItemDefinition.cs | 16 +-
.../JsonApiDotNetCoreExample.csproj | 2 +-
.../JsonApiDotNetCoreExample/Program.cs | 7 -
.../MultiDbContextExample.csproj | 2 +-
.../NoEntityFrameworkExample.csproj | 2 +-
.../InMemoryResourceRepository.cs | 4 -
.../Services/InMemoryResourceService.cs | 4 -
.../ReportsExample/ReportsExample.csproj | 2 +-
.../ArgumentGuard.cs | 18 --
.../JsonApiDotNetCore.Annotations.csproj | 2 +-
.../PolyfillCollectionExtensions.cs | 24 +--
.../ReadOnlySet.cs | 171 ++++++++++++++++++
.../Configuration/PageNumber.cs | 7 -
.../Configuration/PageSize.cs | 7 -
.../Diagnostics/DefaultCodeTimerSession.cs | 7 -
.../JsonApiDotNetCore.csproj | 2 +-
.../Queries/QueryLayerComposer.cs | 4 -
test/AnnotationTests/AnnotationTests.csproj | 2 +-
test/DapperTests/DapperTests.csproj | 2 +-
.../IntegrationTests/DapperTestContext.cs | 4 -
.../IntegrationTests/SqlTextAdapter.cs | 4 -
test/DiscoveryTests/DiscoveryTests.csproj | 2 +-
.../ModelState/ModelStateValidationTests.cs | 9 -
.../JsonKebabCaseNamingPolicy.cs | 81 ---------
.../KebabCasingConventionStartup.cs | 5 +-
.../IntegrationTests/ReadWrite/RgbColor.cs | 5 -
.../JsonApiDotNetCoreTests.csproj | 3 +-
.../MultiDbContextTests.csproj | 2 +-
.../NoEntityFrameworkTests.csproj | 2 +-
.../SourceGeneratorTests.csproj | 2 +-
.../CapturingLoggerProvider.cs | 6 +-
.../TestBuildingBlocks/DbContextExtensions.cs | 4 -
.../TestBuildingBlocks.csproj | 2 +-
test/UnitTests/UnitTests.csproj | 2 +-
45 files changed, 204 insertions(+), 262 deletions(-)
create mode 100644 src/JsonApiDotNetCore.Annotations/ReadOnlySet.cs
delete mode 100644 test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/JsonKebabCaseNamingPolicy.cs
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 8a8437e9aa..89f2c848b8 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -46,7 +46,6 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
- 6.0.x
8.0.x
9.0.x
- name: Show installed versions
@@ -165,7 +164,6 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
- 6.0.x
8.0.x
9.0.x
- name: Git checkout
@@ -221,7 +219,6 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
- 6.0.x
8.0.x
9.0.x
- name: Git checkout
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 5abd2b1dc0..92e716594d 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -27,7 +27,6 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
- 6.0.x
8.0.x
9.0.x
- name: Git checkout
diff --git a/Directory.Build.props b/Directory.Build.props
index 4e8f6cd101..5fddbdf8ab 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -52,11 +52,6 @@
$(NoWarn);CA1062
-
-
- $(NoWarn);SYSLIB1006
-
-
diff --git a/JsonApiDotNetCore.sln.DotSettings b/JsonApiDotNetCore.sln.DotSettings
index 5878341db6..7151bb82c8 100644
--- a/JsonApiDotNetCore.sln.DotSettings
+++ b/JsonApiDotNetCore.sln.DotSettings
@@ -14,6 +14,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);
3000
50
False
+ 83FF097C-C8C6-477B-9FAB-DF99B84978B5/f:ReadOnlySet.cs
SOLUTION
True
True
diff --git a/README.md b/README.md
index 3354eac45b..8bd84b3d9c 100644
--- a/README.md
+++ b/README.md
@@ -87,13 +87,9 @@ See also our [versioning policy](./VERSIONING_POLICY.md).
| | | 7 | 7 |
| | | 8 | 8, 9 |
| | | 9 | 9 |
-| master | Preview | 6 | 6, 7 |
-| | | 7 | 7 |
-| | | 8 | 8, 9 |
+| master | Preview | 8 | 8, 9 |
| | | 9 | 9 |
-| openapi | Experimental | 6 | 6, 7 |
-| | | 7 | 7 |
-| | | 8 | 8, 9 |
+| openapi | Experimental | 8 | 8, 9 |
| | | 9 | 9 |
## Contributing
diff --git a/package-versions.props b/package-versions.props
index b5d2f30cb3..00e8462550 100644
--- a/package-versions.props
+++ b/package-versions.props
@@ -15,6 +15,7 @@
2.4.*
2.0.*
8.0.*
+ 9.0.*
17.11.*
2.9.*
2.8.*
@@ -28,7 +29,6 @@
9.0.*
9.0.*
9.0.0-*
- $(AspNetCoreVersion)
@@ -39,18 +39,5 @@
8.0.*
8.0.*
$(EntityFrameworkCoreVersion)
- $(AspNetCoreVersion)
-
-
-
-
- 6.0.0
-
-
- 6.0.*
- 2.1.*
- 7.0.*
- $(EntityFrameworkCoreVersion)
- 8.0.*
diff --git a/src/Examples/DapperExample/DapperExample.csproj b/src/Examples/DapperExample/DapperExample.csproj
index 2d3fad689d..ed7bd358eb 100644
--- a/src/Examples/DapperExample/DapperExample.csproj
+++ b/src/Examples/DapperExample/DapperExample.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/Examples/DapperExample/Program.cs b/src/Examples/DapperExample/Program.cs
index 31e5814e5b..f68d480564 100644
--- a/src/Examples/DapperExample/Program.cs
+++ b/src/Examples/DapperExample/Program.cs
@@ -31,10 +31,10 @@
}
case DatabaseProvider.MySql:
{
-#if NET9_0_OR_GREATER
- ServerVersion serverVersion = await ServerVersion.AutoDetectAsync(connectionString);
-#else
+#if NET8_0
ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
+#else
+ ServerVersion serverVersion = await ServerVersion.AutoDetectAsync(connectionString);
#endif
builder.Services.AddMySql(connectionString, serverVersion, optionsAction: options => SetDbContextDebugOptions(options));
diff --git a/src/Examples/DapperExample/Repositories/ResultSetMapper.cs b/src/Examples/DapperExample/Repositories/ResultSetMapper.cs
index 1b20f74dd9..89a7890fd0 100644
--- a/src/Examples/DapperExample/Repositories/ResultSetMapper.cs
+++ b/src/Examples/DapperExample/Repositories/ResultSetMapper.cs
@@ -3,9 +3,6 @@
using JsonApiDotNetCore.Queries.Expressions;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;
-#if NET6_0
-using JsonApiDotNetCore;
-#endif
namespace DapperExample.Repositories;
diff --git a/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj b/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj
index a22b938ba0..3edc993428 100644
--- a/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj
+++ b/src/Examples/DatabasePerTenantExample/DatabasePerTenantExample.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/Examples/GettingStarted/GettingStarted.csproj b/src/Examples/GettingStarted/GettingStarted.csproj
index 22fc0529b1..611aeb37a5 100644
--- a/src/Examples/GettingStarted/GettingStarted.csproj
+++ b/src/Examples/GettingStarted/GettingStarted.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/Examples/JsonApiDotNetCoreExample/Definitions/TodoItemDefinition.cs b/src/Examples/JsonApiDotNetCoreExample/Definitions/TodoItemDefinition.cs
index cd85ccd696..aab9369618 100644
--- a/src/Examples/JsonApiDotNetCoreExample/Definitions/TodoItemDefinition.cs
+++ b/src/Examples/JsonApiDotNetCoreExample/Definitions/TodoItemDefinition.cs
@@ -5,28 +5,14 @@
using JsonApiDotNetCore.Queries.Expressions;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCoreExample.Models;
-#if NET6_0
-using Microsoft.AspNetCore.Authentication;
-#endif
namespace JsonApiDotNetCoreExample.Definitions;
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
-public sealed class TodoItemDefinition(
- IResourceGraph resourceGraph,
-#if NET6_0
- ISystemClock systemClock
-#else
- TimeProvider timeProvider
-#endif
-)
+public sealed class TodoItemDefinition(IResourceGraph resourceGraph, TimeProvider timeProvider)
: JsonApiResourceDefinition(resourceGraph)
{
-#if NET6_0
- private readonly Func _getUtcNow = () => systemClock.UtcNow;
-#else
private readonly Func _getUtcNow = timeProvider.GetUtcNow;
-#endif
public override SortExpression OnApplySort(SortExpression? existingSort)
{
diff --git a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
index a22b938ba0..3edc993428 100644
--- a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
+++ b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/Examples/JsonApiDotNetCoreExample/Program.cs b/src/Examples/JsonApiDotNetCoreExample/Program.cs
index 4c11a71660..2cfa1e640d 100644
--- a/src/Examples/JsonApiDotNetCoreExample/Program.cs
+++ b/src/Examples/JsonApiDotNetCoreExample/Program.cs
@@ -8,9 +8,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection.Extensions;
-#if NET6_0
-using Microsoft.AspNetCore.Authentication;
-#endif
[assembly: ExcludeFromCodeCoverage]
@@ -48,11 +45,7 @@ static void ConfigureServices(WebApplicationBuilder builder)
{
using IDisposable _ = CodeTimingSessionManager.Current.Measure("Configure services");
-#if NET6_0
- builder.Services.TryAddSingleton();
-#else
builder.Services.TryAddSingleton(TimeProvider.System);
-#endif
builder.Services.AddDbContext(options =>
{
diff --git a/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj b/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj
index 22fc0529b1..611aeb37a5 100644
--- a/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj
+++ b/src/Examples/MultiDbContextExample/MultiDbContextExample.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj b/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj
index c45552dc2d..15a485c08f 100644
--- a/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj
+++ b/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/Examples/NoEntityFrameworkExample/Repositories/InMemoryResourceRepository.cs b/src/Examples/NoEntityFrameworkExample/Repositories/InMemoryResourceRepository.cs
index 9eba0b8326..4feb370858 100644
--- a/src/Examples/NoEntityFrameworkExample/Repositories/InMemoryResourceRepository.cs
+++ b/src/Examples/NoEntityFrameworkExample/Repositories/InMemoryResourceRepository.cs
@@ -32,11 +32,7 @@ public Task> GetAsync(QueryLayer queryLayer, Canc
IEnumerable dataSource = GetDataSource();
IEnumerable resources = _queryLayerToLinqConverter.ApplyQueryLayer(queryLayer, dataSource);
-#if NET6_0
- return Task.FromResult>(Array.AsReadOnly(resources.ToArray()));
-#else
return Task.FromResult>(resources.ToArray().AsReadOnly());
-#endif
}
///
diff --git a/src/Examples/NoEntityFrameworkExample/Services/InMemoryResourceService.cs b/src/Examples/NoEntityFrameworkExample/Services/InMemoryResourceService.cs
index e55b9340b6..0dcc5d9905 100644
--- a/src/Examples/NoEntityFrameworkExample/Services/InMemoryResourceService.cs
+++ b/src/Examples/NoEntityFrameworkExample/Services/InMemoryResourceService.cs
@@ -65,11 +65,7 @@ public Task> GetAsync(CancellationToken cancellat
_paginationContext.IsPageFull = true;
}
-#if NET6_0
- return Task.FromResult>(Array.AsReadOnly(resources));
-#else
return Task.FromResult>(resources.AsReadOnly());
-#endif
}
private void LogFiltersInTopScope()
diff --git a/src/Examples/ReportsExample/ReportsExample.csproj b/src/Examples/ReportsExample/ReportsExample.csproj
index 3f2c288b23..6ade1386be 100644
--- a/src/Examples/ReportsExample/ReportsExample.csproj
+++ b/src/Examples/ReportsExample/ReportsExample.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs b/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs
index e01b80d776..137654fb3e 100644
--- a/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs
+++ b/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs
@@ -30,30 +30,12 @@ public static void NotNullNorEmpty([SysNotNull] IEnumerable? value, [Calle
[AssertionMethod]
public static void NotNullNorEmpty([SysNotNull] string? value, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
{
-#if !NET6_0
ArgumentException.ThrowIfNullOrEmpty(value, parameterName);
-#else
- ArgumentNullException.ThrowIfNull(value, parameterName);
-
- if (value.Length == 0)
- {
- throw new ArgumentException("String cannot be null or empty.", parameterName);
- }
-#endif
}
[AssertionMethod]
public static void NotNullNorWhitespace([SysNotNull] string? value, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
{
-#if !NET6_0
ArgumentException.ThrowIfNullOrWhiteSpace(value, parameterName);
-#else
- ArgumentNullException.ThrowIfNull(value, parameterName);
-
- if (string.IsNullOrWhiteSpace(value))
- {
- throw new ArgumentException("String cannot be null, empty, or whitespace.", parameterName);
- }
-#endif
}
}
diff --git a/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj b/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj
index 04238621da..09968a0922 100644
--- a/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj
+++ b/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0;netstandard1.0
+ net8.0;netstandard1.0
true
true
JsonApiDotNetCore
diff --git a/src/JsonApiDotNetCore.Annotations/PolyfillCollectionExtensions.cs b/src/JsonApiDotNetCore.Annotations/PolyfillCollectionExtensions.cs
index 72578e5db2..efc51f4f17 100644
--- a/src/JsonApiDotNetCore.Annotations/PolyfillCollectionExtensions.cs
+++ b/src/JsonApiDotNetCore.Annotations/PolyfillCollectionExtensions.cs
@@ -1,10 +1,4 @@
-#if NET6_0
using System.Collections.ObjectModel;
-#endif
-
-#if NET6_0
-#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
-#endif
namespace JsonApiDotNetCore;
@@ -13,22 +7,6 @@ internal static class PolyfillCollectionExtensions
{
public static IReadOnlySet AsReadOnly(this HashSet source)
{
- // We can't use ReadOnlySet yet, which is being introduced in .NET 9.
- return source;
- }
-
-#if NET6_0
- public static ReadOnlyDictionary AsReadOnly(this IDictionary source)
- where TKey : notnull
- {
- // The AsReadOnly() extension method is unavailable in .NET 6.
- return new ReadOnlyDictionary(source);
- }
-
- public static ReadOnlyCollection AsReadOnly(this T[] source)
- {
- // The AsReadOnly() extension method is unavailable in .NET 6.
- return Array.AsReadOnly(source);
+ return new ReadOnlySet(source);
}
-#endif
}
diff --git a/src/JsonApiDotNetCore.Annotations/ReadOnlySet.cs b/src/JsonApiDotNetCore.Annotations/ReadOnlySet.cs
new file mode 100644
index 0000000000..9917af9ec7
--- /dev/null
+++ b/src/JsonApiDotNetCore.Annotations/ReadOnlySet.cs
@@ -0,0 +1,171 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if NET8_0
+#pragma warning disable
+
+// ReadOnlySet was introduced in .NET 9.
+// This file was copied from https://github.com/dotnet/runtime/blob/release/9.0/src/libraries/System.Collections/src/System/Collections/Generic/ReadOnlySet.cs
+// and made internal to enable usage on lower .NET versions.
+
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+
+namespace System.Collections.ObjectModel;
+
+/// Represents a read-only, generic set of values.
+/// The type of values in the set.
+[DebuggerDisplay("Count = {Count}")]
+[ExcludeFromCodeCoverage]
+internal class ReadOnlySet : IReadOnlySet, ISet, ICollection
+{
+ /// The wrapped set.
+ private readonly ISet _set;
+
+ /// Initializes a new instance of the class that is a wrapper around the specified set.
+ /// The set to wrap.
+ public ReadOnlySet(ISet set)
+ {
+ ArgumentNullException.ThrowIfNull(set);
+ _set = set;
+ }
+
+ /// Gets an empty .
+ public static ReadOnlySet Empty { get; } = new ReadOnlySet(new HashSet());
+
+ /// Gets the set that is wrapped by this object.
+ protected ISet Set => _set;
+
+ ///
+ public int Count => _set.Count;
+
+ ///
+ public IEnumerator GetEnumerator() =>
+ _set.Count == 0 ? ((IEnumerable)Array.Empty()).GetEnumerator() :
+ _set.GetEnumerator();
+
+ ///
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
+
+ ///
+ public bool Contains(T item) => _set.Contains(item);
+
+ ///
+ public bool IsProperSubsetOf(IEnumerable other) => _set.IsProperSubsetOf(other);
+
+ ///
+ public bool IsProperSupersetOf(IEnumerable other) => _set.IsProperSupersetOf(other);
+
+ ///
+ public bool IsSubsetOf(IEnumerable other) => _set.IsSubsetOf(other);
+
+ ///
+ public bool IsSupersetOf(IEnumerable other) => _set.IsSupersetOf(other);
+
+ ///
+ public bool Overlaps(IEnumerable other) => _set.Overlaps(other);
+
+ ///
+ public bool SetEquals(IEnumerable other) => _set.SetEquals(other);
+
+ ///
+ void ICollection.CopyTo(T[] array, int arrayIndex) => _set.CopyTo(array, arrayIndex);
+
+ ///
+ void ICollection.CopyTo(Array array, int index) => CollectionHelpers.CopyTo(_set, array, index);
+
+ ///
+ bool ICollection.IsReadOnly => true;
+
+ ///
+ bool ICollection.IsSynchronized => false;
+
+ ///
+ object ICollection.SyncRoot => _set is ICollection c ? c.SyncRoot : this;
+
+ ///
+ bool ISet.Add(T item) => throw new NotSupportedException();
+
+ ///
+ void ISet.ExceptWith(IEnumerable other) => throw new NotSupportedException();
+
+ ///
+ void ISet.IntersectWith(IEnumerable other) => throw new NotSupportedException();
+
+ ///
+ void ISet.SymmetricExceptWith(IEnumerable other) => throw new NotSupportedException();
+
+ ///
+ void ISet.UnionWith(IEnumerable other) => throw new NotSupportedException();
+
+ ///
+ void ICollection.Add(T item) => throw new NotSupportedException();
+
+ ///
+ void ICollection.Clear() => throw new NotSupportedException();
+
+ ///
+ bool ICollection.Remove(T item) => throw new NotSupportedException();
+
+ private static class CollectionHelpers
+ {
+ private static void ValidateCopyToArguments(int sourceCount, Array array, int index)
+ {
+ ArgumentNullException.ThrowIfNull(array);
+
+ if (array.Rank != 1)
+ {
+ throw new ArgumentException("Only single dimensional arrays are supported for the requested action.", nameof(array));
+ }
+
+ if (array.GetLowerBound(0) != 0)
+ {
+ throw new ArgumentException("The lower bound of target array must be zero.", nameof(array));
+ }
+
+ ArgumentOutOfRangeException.ThrowIfNegative(index);
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(index, array.Length);
+
+ if (array.Length - index < sourceCount)
+ {
+ throw new ArgumentException("Destination array is not long enough to copy all the items in the collection. Check array index and length.");
+ }
+ }
+
+ internal static void CopyTo(ICollection collection, Array array, int index)
+ {
+ ValidateCopyToArguments(collection.Count, array, index);
+
+ if (collection is ICollection nonGenericCollection)
+ {
+ // Easy out if the ICollection implements the non-generic ICollection
+ nonGenericCollection.CopyTo(array, index);
+ }
+ else if (array is T[] items)
+ {
+ collection.CopyTo(items, index);
+ }
+ else
+ {
+ // We can't cast array of value type to object[], so we don't support widening of primitive types here.
+ if (array is not object?[] objects)
+ {
+ throw new ArgumentException("Target array type is not compatible with the type of items in the collection.", nameof(array));
+ }
+
+ try
+ {
+ foreach (T item in collection)
+ {
+ objects[index++] = item;
+ }
+ }
+ catch (ArrayTypeMismatchException)
+ {
+ throw new ArgumentException("Target array type is not compatible with the type of items in the collection.", nameof(array));
+ }
+ }
+ }
+ }
+}
+#endif
diff --git a/src/JsonApiDotNetCore/Configuration/PageNumber.cs b/src/JsonApiDotNetCore/Configuration/PageNumber.cs
index 44732fc404..f4af725a3d 100644
--- a/src/JsonApiDotNetCore/Configuration/PageNumber.cs
+++ b/src/JsonApiDotNetCore/Configuration/PageNumber.cs
@@ -11,14 +11,7 @@ public sealed class PageNumber : IEquatable
public PageNumber(int oneBasedValue)
{
-#if NET6_0
- if (oneBasedValue < 1)
- {
- throw new ArgumentOutOfRangeException(nameof(oneBasedValue));
- }
-#else
ArgumentOutOfRangeException.ThrowIfLessThan(oneBasedValue, 1);
-#endif
OneBasedValue = oneBasedValue;
}
diff --git a/src/JsonApiDotNetCore/Configuration/PageSize.cs b/src/JsonApiDotNetCore/Configuration/PageSize.cs
index 46beb1419f..4581992597 100644
--- a/src/JsonApiDotNetCore/Configuration/PageSize.cs
+++ b/src/JsonApiDotNetCore/Configuration/PageSize.cs
@@ -9,14 +9,7 @@ public sealed class PageSize : IEquatable
public PageSize(int value)
{
-#if NET6_0
- if (value < 1)
- {
- throw new ArgumentOutOfRangeException(nameof(value));
- }
-#else
ArgumentOutOfRangeException.ThrowIfLessThan(value, 1);
-#endif
Value = value;
}
diff --git a/src/JsonApiDotNetCore/Diagnostics/DefaultCodeTimerSession.cs b/src/JsonApiDotNetCore/Diagnostics/DefaultCodeTimerSession.cs
index 5737dbe3f2..df782bb8c0 100644
--- a/src/JsonApiDotNetCore/Diagnostics/DefaultCodeTimerSession.cs
+++ b/src/JsonApiDotNetCore/Diagnostics/DefaultCodeTimerSession.cs
@@ -27,14 +27,7 @@ public DefaultCodeTimerSession()
private void AssertNotDisposed()
{
-#if NET6_0
- if (_codeTimerInContext.Value == null)
- {
- throw new ObjectDisposedException(nameof(DefaultCodeTimerSession));
- }
-#else
ObjectDisposedException.ThrowIf(_codeTimerInContext.Value == null, this);
-#endif
}
public void Dispose()
diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
index 0f395511a7..b30f89cb9f 100644
--- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
+++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
@@ -1,6 +1,6 @@
- net8.0;net6.0
+ net8.0
true
true
diff --git a/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs b/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs
index 1804027de4..0c704d0013 100644
--- a/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs
+++ b/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs
@@ -135,11 +135,7 @@ public QueryLayer ComposeFromConstraints(ResourceType requestResourceType)
{
ArgumentGuard.NotNull(requestResourceType);
-#if NET6_0
- ImmutableArray constraints = _constraintProviders.SelectMany(provider => provider.GetConstraints()).ToImmutableArray();
-#else
ImmutableArray constraints = [.. _constraintProviders.SelectMany(provider => provider.GetConstraints())];
-#endif
QueryLayer topLayer = ComposeTopLayer(constraints, requestResourceType);
topLayer.Include = ComposeChildren(topLayer, constraints);
diff --git a/test/AnnotationTests/AnnotationTests.csproj b/test/AnnotationTests/AnnotationTests.csproj
index 7c5e5f3ae0..885e9f769c 100644
--- a/test/AnnotationTests/AnnotationTests.csproj
+++ b/test/AnnotationTests/AnnotationTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0;netstandard2.0
+ net9.0;net8.0;netstandard2.0
diff --git a/test/DapperTests/DapperTests.csproj b/test/DapperTests/DapperTests.csproj
index 1420e0dd60..7d41d78911 100644
--- a/test/DapperTests/DapperTests.csproj
+++ b/test/DapperTests/DapperTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/test/DapperTests/IntegrationTests/DapperTestContext.cs b/test/DapperTests/IntegrationTests/DapperTestContext.cs
index 9fdc330c74..01747dde1d 100644
--- a/test/DapperTests/IntegrationTests/DapperTestContext.cs
+++ b/test/DapperTests/IntegrationTests/DapperTestContext.cs
@@ -122,14 +122,10 @@ public async Task ClearAllTablesAsync(DbContext dbContext)
_ => throw new NotSupportedException($"Unsupported database provider '{databaseProvider}'.")
};
-#if !NET6_0
#pragma warning disable EF1002 // Risk of vulnerability to SQL injection.
-#endif
// Justification: Table names cannot be parameterized.
await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {escapedTableName}");
-#if !NET6_0
#pragma warning restore EF1002 // Risk of vulnerability to SQL injection.
-#endif
}
}
}
diff --git a/test/DapperTests/IntegrationTests/SqlTextAdapter.cs b/test/DapperTests/IntegrationTests/SqlTextAdapter.cs
index 3bdeab115f..1d6d45555e 100644
--- a/test/DapperTests/IntegrationTests/SqlTextAdapter.cs
+++ b/test/DapperTests/IntegrationTests/SqlTextAdapter.cs
@@ -5,11 +5,7 @@ namespace DapperTests.IntegrationTests;
internal sealed class SqlTextAdapter(DatabaseProvider databaseProvider)
{
-#if NET6_0
- private const RegexOptions Options = RegexOptions.Compiled | RegexOptions.CultureInvariant;
-#else
private const RegexOptions Options = RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.NonBacktracking;
-#endif
private static readonly Dictionary SqlServerReplacements = new()
{
diff --git a/test/DiscoveryTests/DiscoveryTests.csproj b/test/DiscoveryTests/DiscoveryTests.csproj
index 295d5340fa..abeaaa956d 100644
--- a/test/DiscoveryTests/DiscoveryTests.csproj
+++ b/test/DiscoveryTests/DiscoveryTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs
index 93cdf43453..68e7207e4a 100644
--- a/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs
+++ b/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs
@@ -3,9 +3,6 @@
using JsonApiDotNetCore.Serialization.Objects;
using TestBuildingBlocks;
using Xunit;
-#if NET6_0
-using Microsoft.Extensions.DependencyInjection;
-#endif
namespace JsonApiDotNetCoreTests.IntegrationTests.InputValidation.ModelState;
@@ -20,12 +17,6 @@ public ModelStateValidationTests(IntegrationTestContext();
testContext.UseController();
-
-#if NET6_0
- testContext.ConfigureServices(services =>
- // Polyfill for missing DateOnly/TimeOnly support in .NET 6 ModelState validation.
- services.AddDateOnlyTimeOnlyStringConverters());
-#endif
}
[Fact]
diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/JsonKebabCaseNamingPolicy.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/JsonKebabCaseNamingPolicy.cs
deleted file mode 100644
index 1d2f948068..0000000000
--- a/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/JsonKebabCaseNamingPolicy.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-using System.Text;
-using System.Text.Json;
-
-namespace JsonApiDotNetCoreTests.IntegrationTests.NamingConventions;
-
-// Based on https://github.com/J0rgeSerran0/JsonNamingPolicy
-internal sealed class JsonKebabCaseNamingPolicy : JsonNamingPolicy
-{
- private const char Separator = '-';
-
- public static readonly JsonKebabCaseNamingPolicy Instance = new();
-
- public override string ConvertName(string name)
- {
- if (string.IsNullOrWhiteSpace(name))
- {
- return string.Empty;
- }
-
- ReadOnlySpan spanName = name.Trim();
-
- var stringBuilder = new StringBuilder();
- bool addCharacter = true;
-
- bool isNextLower = false;
- bool isNextUpper = false;
- bool isNextSpace = false;
-
- for (int position = 0; position < spanName.Length; position++)
- {
- if (position != 0)
- {
- bool isCurrentSpace = spanName[position] == 32;
- bool isPreviousSpace = spanName[position - 1] == 32;
- bool isPreviousSeparator = spanName[position - 1] == 95;
-
- if (position + 1 != spanName.Length)
- {
- isNextLower = spanName[position + 1] is >= 'a' and <= 'z';
- isNextUpper = spanName[position + 1] is >= 'A' and <= 'Z';
- isNextSpace = spanName[position + 1] == ' ';
- }
-
- if (isCurrentSpace && (isPreviousSpace || isPreviousSeparator || isNextUpper || isNextSpace))
- {
- addCharacter = false;
- }
- else
- {
- bool isCurrentUpper = spanName[position] is >= 'A' and <= 'Z';
- bool isPreviousLower = spanName[position - 1] is >= 'a' and <= 'z';
- bool isPreviousNumber = spanName[position - 1] is >= '0' and <= '9';
-
- if (isCurrentUpper && (isPreviousLower || isPreviousNumber || isNextLower || isNextSpace))
- {
- stringBuilder.Append(Separator);
- }
- else
- {
- if (isCurrentSpace)
- {
- stringBuilder.Append(Separator);
- addCharacter = false;
- }
- }
- }
- }
-
- if (addCharacter)
- {
- stringBuilder.Append(spanName[position]);
- }
- else
- {
- addCharacter = true;
- }
- }
-
- return stringBuilder.ToString().ToLowerInvariant();
- }
-}
diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/KebabCasingConventionStartup.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/KebabCasingConventionStartup.cs
index da3d3b10f9..6321943718 100644
--- a/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/KebabCasingConventionStartup.cs
+++ b/test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/KebabCasingConventionStartup.cs
@@ -1,3 +1,4 @@
+using System.Text.Json;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using TestBuildingBlocks;
@@ -16,7 +17,7 @@ protected override void SetJsonApiOptions(JsonApiOptions options)
options.UseRelativeLinks = true;
options.IncludeTotalResourceCount = true;
- options.SerializerOptions.PropertyNamingPolicy = JsonKebabCaseNamingPolicy.Instance;
- options.SerializerOptions.DictionaryKeyPolicy = JsonKebabCaseNamingPolicy.Instance;
+ options.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.KebabCaseLower;
+ options.SerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.KebabCaseLower;
}
}
diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/RgbColor.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/RgbColor.cs
index 8eeabbee1d..28762384c9 100644
--- a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/RgbColor.cs
+++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/RgbColor.cs
@@ -8,11 +8,6 @@ namespace JsonApiDotNetCoreTests.IntegrationTests.ReadWrite;
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.ReadWrite")]
public sealed class RgbColor : Identifiable
{
-#if NET6_0
- // Workaround for bug in .NET 6, see https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1153.
- public override string? Id { get; set; }
-#endif
-
[Attr]
public string DisplayName { get; set; } = null!;
diff --git a/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj b/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
index 95a623d0f9..6bc5a666a1 100644
--- a/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
+++ b/test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
@@ -13,7 +13,6 @@
-
diff --git a/test/MultiDbContextTests/MultiDbContextTests.csproj b/test/MultiDbContextTests/MultiDbContextTests.csproj
index 6466d8d75f..e80f03c69e 100644
--- a/test/MultiDbContextTests/MultiDbContextTests.csproj
+++ b/test/MultiDbContextTests/MultiDbContextTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
index 968d798be3..4deb6b21cd 100644
--- a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
+++ b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/test/SourceGeneratorTests/SourceGeneratorTests.csproj b/test/SourceGeneratorTests/SourceGeneratorTests.csproj
index 8b7d42fdca..4f487fa168 100644
--- a/test/SourceGeneratorTests/SourceGeneratorTests.csproj
+++ b/test/SourceGeneratorTests/SourceGeneratorTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/test/TestBuildingBlocks/CapturingLoggerProvider.cs b/test/TestBuildingBlocks/CapturingLoggerProvider.cs
index 38ec60ed3a..20503c4248 100644
--- a/test/TestBuildingBlocks/CapturingLoggerProvider.cs
+++ b/test/TestBuildingBlocks/CapturingLoggerProvider.cs
@@ -10,10 +10,10 @@ public sealed class CapturingLoggerProvider : ILoggerProvider
private static readonly Func DefaultFilter = (_, _) => true;
private readonly Func _filter;
-#if NET9_0_OR_GREATER
- private readonly Lock _lockObject = new();
-#else
+#if NET8_0
private readonly object _lockObject = new();
+#else
+ private readonly Lock _lockObject = new();
#endif
private readonly List _messages = [];
diff --git a/test/TestBuildingBlocks/DbContextExtensions.cs b/test/TestBuildingBlocks/DbContextExtensions.cs
index 1d1dbc0650..d3a8a0e8ad 100644
--- a/test/TestBuildingBlocks/DbContextExtensions.cs
+++ b/test/TestBuildingBlocks/DbContextExtensions.cs
@@ -44,14 +44,10 @@ private static async Task ClearTablesAsync(this DbContext dbContext, params Type
}
else
{
-#if !NET6_0
#pragma warning disable EF1002 // Risk of vulnerability to SQL injection.
-#endif
// Justification: Table names cannot be parameterized.
await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM \"{tableName}\"");
-#if !NET6_0
#pragma warning restore EF1002 // Risk of vulnerability to SQL injection.
-#endif
}
}
}
diff --git a/test/TestBuildingBlocks/TestBuildingBlocks.csproj b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
index a6f6ff4299..ddb6edb9dc 100644
--- a/test/TestBuildingBlocks/TestBuildingBlocks.csproj
+++ b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj
index e977ac0c8c..68076a51e1 100644
--- a/test/UnitTests/UnitTests.csproj
+++ b/test/UnitTests/UnitTests.csproj
@@ -1,6 +1,6 @@
- net9.0;net8.0;net6.0
+ net9.0;net8.0
From 5d8badf6cb1e4361d6828f7f4a1fb3123e767a28 Mon Sep 17 00:00:00 2001
From: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Date: Sun, 22 Dec 2024 12:32:02 +0100
Subject: [PATCH 3/8] Inline ArgumentGuard methods
---
JsonApiDotNetCore.sln.DotSettings | 30 +++-------
.../AtomicOperations/AmbientTransaction.cs | 5 +-
.../AmbientTransactionFactory.cs | 7 +--
.../DapperExample/Data/AppDbContext.cs | 3 +-
.../Definitions/TodoItemDefinition.cs | 3 +-
.../FromEntitiesNavigationResolver.cs | 7 +--
.../Repositories/DapperFacade.cs | 18 +++---
.../Repositories/DapperRepository.cs | 38 ++++++------
.../Repositories/ResourceChangeDetector.cs | 8 +--
.../DeleteOneToOneStatementBuilder.cs | 5 +-
.../DeleteResourceStatementBuilder.cs | 2 +-
.../Builders/InsertStatementBuilder.cs | 5 +-
.../Builders/SelectStatementBuilder.cs | 13 ++---
.../Builders/SqlQueryBuilder.cs | 3 +-
.../Builders/StatementBuilder.cs | 3 +-
.../UpdateClearOneToOneStatementBuilder.cs | 7 +--
.../UpdateResourceStatementBuilder.cs | 2 +-
.../DataModel/BaseDataModelService.cs | 9 ++-
.../DataModel/RelationshipForeignKey.cs | 5 +-
.../Generators/UniqueNameGenerator.cs | 4 +-
.../TranslationToSql/SqlCommand.cs | 5 +-
.../ColumnSelectorUsageCollector.cs | 5 +-
.../StaleColumnReferenceRewriter.cs | 5 +-
.../UnusedSelectorsRewriter.cs | 5 +-
.../TreeNodes/ColumnAssignmentNode.cs | 6 +-
.../TreeNodes/ColumnInSelectNode.cs | 4 +-
.../TranslationToSql/TreeNodes/ColumnNode.cs | 4 +-
.../TreeNodes/ColumnSelectorNode.cs | 4 +-
.../TreeNodes/ComparisonNode.cs | 5 +-
.../TranslationToSql/TreeNodes/CountNode.cs | 4 +-
.../TranslationToSql/TreeNodes/DeleteNode.cs | 6 +-
.../TranslationToSql/TreeNodes/ExistsNode.cs | 4 +-
.../TranslationToSql/TreeNodes/InNode.cs | 2 +-
.../TranslationToSql/TreeNodes/InsertNode.cs | 2 +-
.../TranslationToSql/TreeNodes/JoinNode.cs | 6 +-
.../TranslationToSql/TreeNodes/LikeNode.cs | 5 +-
.../TranslationToSql/TreeNodes/LogicalNode.cs | 3 +-
.../TranslationToSql/TreeNodes/NotNode.cs | 4 +-
.../TreeNodes/OrderByColumnNode.cs | 4 +-
.../TreeNodes/OrderByCountNode.cs | 4 +-
.../TreeNodes/ParameterNode.cs | 4 +-
.../TreeNodes/TableAccessorNode.cs | 4 +-
.../TranslationToSql/TreeNodes/TableNode.cs | 5 +-
.../TranslationToSql/TreeNodes/UpdateNode.cs | 4 +-
.../TranslationToSql/TreeNodes/WhereNode.cs | 4 +-
.../ArgumentGuard.cs | 19 ------
.../CollectionConverter.cs | 6 +-
.../Configuration/ResourceType.cs | 16 ++---
.../Resources/Annotations/HasManyAttribute.cs | 6 +-
.../Annotations/RelationshipAttribute.cs | 2 +-
.../Annotations/ResourceFieldAttribute.cs | 8 +--
.../Resources/RuntimeTypeConverter.cs | 6 +-
.../TypeExtensions.cs | 4 +-
.../DefaultOperationFilter.cs | 4 +-
.../EntityFrameworkCoreTransaction.cs | 4 +-
.../EntityFrameworkCoreTransactionFactory.cs | 4 +-
.../AtomicOperations/LocalIdTracker.cs | 14 ++---
.../AtomicOperations/LocalIdValidator.cs | 6 +-
.../OperationProcessorAccessor.cs | 6 +-
.../AtomicOperations/OperationsProcessor.cs | 20 +++----
.../Processors/AddToRelationshipProcessor.cs | 4 +-
.../Processors/CreateProcessor.cs | 6 +-
.../Processors/DeleteProcessor.cs | 4 +-
.../RemoveFromRelationshipProcessor.cs | 4 +-
.../Processors/SetRelationshipProcessor.cs | 4 +-
.../Processors/UpdateProcessor.cs | 4 +-
.../RevertRequestStateOnDispose.cs | 2 +-
src/JsonApiDotNetCore/CollectionExtensions.cs | 6 +-
.../ApplicationBuilderExtensions.cs | 2 +-
.../DefaultJsonApiApplicationBuilderEvents.cs | 2 +-
.../InjectablesAssemblyScanner.cs | 4 +-
.../InverseNavigationResolver.cs | 4 +-
.../JsonApiApplicationBuilder.cs | 8 +--
.../JsonApiModelMetadataProvider.cs | 2 +-
.../Configuration/JsonApiOptions.cs | 2 +-
.../Configuration/JsonApiValidationFilter.cs | 2 +-
.../Configuration/ResourceDescriptor.cs | 4 +-
.../Configuration/ResourceGraph.cs | 12 ++--
.../Configuration/ResourceGraphBuilder.cs | 8 +--
.../Configuration/ResourceNameFormatter.cs | 2 +-
.../Configuration/ResourcesAssemblyScanner.cs | 4 +-
.../ServiceCollectionExtensions.cs | 8 +--
.../Configuration/ServiceDiscoveryFacade.cs | 4 +-
.../Configuration/TypeLocator.cs | 10 ++--
.../DisableQueryStringAttribute.cs | 2 +-
.../Controllers/BaseJsonApiController.cs | 24 ++++----
.../BaseJsonApiOperationsController.cs | 20 +++----
.../Controllers/CoreJsonApiController.cs | 2 +-
.../Diagnostics/AspNetCodeTimerSession.cs | 4 +-
.../Diagnostics/CodeTimingSessionManager.cs | 2 +-
.../Errors/InvalidModelStateException.cs | 20 +++----
.../Errors/JsonApiException.cs | 2 +-
.../Errors/MissingResourceInRelationship.cs | 6 +-
.../UnsuccessfulActionResultException.cs | 2 +-
.../AsyncConvertEmptyActionResultFilter.cs | 4 +-
.../Middleware/AsyncJsonApiExceptionFilter.cs | 4 +-
.../AsyncQueryStringActionFilter.cs | 6 +-
.../Middleware/ExceptionHandler.cs | 12 ++--
.../Middleware/HttpContextExtensions.cs | 4 +-
.../HttpMethodAttributeExtensions.cs | 2 +-
.../Middleware/JsonApiContentNegotiator.cs | 4 +-
.../Middleware/JsonApiInputFormatter.cs | 4 +-
.../Middleware/JsonApiMediaType.cs | 4 +-
.../Middleware/JsonApiMediaTypeExtension.cs | 2 +-
.../Middleware/JsonApiMiddleware.cs | 14 ++---
.../Middleware/JsonApiOutputFormatter.cs | 4 +-
.../Middleware/JsonApiRequest.cs | 2 +-
.../Middleware/JsonApiRoutingConvention.cs | 10 ++--
.../Queries/EvaluatedIncludeCache.cs | 4 +-
.../Queries/ExpressionInScope.cs | 2 +-
.../Queries/Expressions/AnyExpression.cs | 2 +-
.../Expressions/ComparisonExpression.cs | 4 +-
.../Queries/Expressions/CountExpression.cs | 2 +-
.../Queries/Expressions/HasExpression.cs | 2 +-
.../Expressions/IncludeChainConverter.cs | 2 +-
.../Expressions/IncludeElementExpression.cs | 4 +-
.../Queries/Expressions/IsTypeExpression.cs | 2 +-
.../Expressions/LiteralConstantExpression.cs | 6 +-
.../Queries/Expressions/LogicalExpression.cs | 4 +-
.../Expressions/MatchTextExpression.cs | 4 +-
.../Queries/Expressions/NotExpression.cs | 2 +-
.../Expressions/PaginationExpression.cs | 2 +-
.../QueryStringParameterScopeExpression.cs | 2 +-
.../Expressions/QueryableHandlerExpression.cs | 2 +-
.../ResourceFieldChainExpression.cs | 2 +-
.../Expressions/SortElementExpression.cs | 2 +-
.../SparseFieldSetExpressionExtensions.cs | 8 +--
.../Queries/FieldSelection.cs | 2 +-
.../Queries/FieldSelectors.cs | 10 ++--
.../Queries/Parsing/FilterParser.cs | 18 +++---
.../Queries/Parsing/IncludeParser.cs | 10 ++--
.../Queries/Parsing/PaginationParser.cs | 6 +-
.../Queries/Parsing/QueryExpressionParser.cs | 10 ++--
.../Queries/Parsing/QueryParseException.cs | 2 +-
.../QueryStringParameterScopeParser.cs | 8 +--
.../Queries/Parsing/QueryTokenizer.cs | 2 +-
.../Queries/Parsing/SortParser.cs | 12 ++--
.../Queries/Parsing/SparseFieldSetParser.cs | 6 +-
.../Queries/Parsing/SparseFieldTypeParser.cs | 2 +-
src/JsonApiDotNetCore/Queries/QueryLayer.cs | 2 +-
.../Queries/QueryLayerComposer.cs | 58 +++++++++----------
.../QueryableBuilding/IncludeClauseBuilder.cs | 2 +-
.../Queries/QueryableBuilding/LambdaScope.cs | 8 +--
.../QueryableBuilding/LambdaScopeFactory.cs | 4 +-
.../QueryableBuilding/OrderClauseBuilder.cs | 2 +-
.../QueryClauseBuilderContext.cs | 18 +++---
.../QueryLayerIncludeConverter.cs | 2 +-
.../QueryableBuilding/QueryableBuilder.cs | 54 ++++++++---------
.../QueryableBuilderContext.cs | 24 ++++----
.../QueryableBuilding/SelectClauseBuilder.cs | 6 +-
.../SkipTakeClauseBuilder.cs | 2 +-
.../QueryableBuilding/WhereClauseBuilder.cs | 2 +-
.../Queries/SparseFieldSetCache.cs | 10 ++--
.../Queries/SystemExpressionBuilder.cs | 2 +-
.../FieldChains/FieldChainParser.cs | 2 +-
.../FieldChains/FieldChainPattern.cs | 4 +-
.../QueryStrings/FieldChains/MatchState.cs | 8 +--
.../FieldChains/MatchTraceScope.cs | 12 ++--
.../PatternDescriptionFormatter.cs | 2 +-
.../FieldChains/PatternMatchResult.cs | 4 +-
.../FieldChains/PatternMatcher.cs | 8 +--
.../QueryStrings/FieldChains/PatternParser.cs | 2 +-
.../FieldChains/PatternTextFormatter.cs | 2 +-
.../FilterQueryStringParameterReader.cs | 10 ++--
.../IncludeQueryStringParameterReader.cs | 6 +-
.../LegacyFilterNotationConverter.cs | 6 +-
.../PaginationQueryStringParameterReader.cs | 12 ++--
.../QueryStringParameterReader.cs | 4 +-
.../QueryStrings/QueryStringReader.cs | 8 +--
.../RequestQueryStringAccessor.cs | 2 +-
...ourceDefinitionQueryableParameterReader.cs | 6 +-
.../SortQueryStringParameterReader.cs | 8 +--
...parseFieldSetQueryStringParameterReader.cs | 8 +--
.../Repositories/DbContextExtensions.cs | 10 ++--
.../Repositories/DbContextResolver.cs | 2 +-
.../EntityFrameworkCoreRepository.cs | 46 +++++++--------
.../ResourceRepositoryAccessor.cs | 42 +++++++-------
.../Resources/AbstractResourceWrapper.cs | 2 +-
.../Resources/IdentifiableExtensions.cs | 4 +-
.../Resources/JsonApiResourceDefinition.cs | 2 +-
.../Resources/OperationContainer.cs | 8 +--
.../Resources/ResourceChangeTracker.cs | 10 ++--
.../Resources/ResourceDefinitionAccessor.cs | 54 ++++++++---------
.../Resources/ResourceFactory.cs | 6 +-
.../SortExpressionLambdaConverter.cs | 4 +-
.../Resources/TargetedFields.cs | 2 +-
.../JsonConverters/JsonObjectConverter.cs | 4 +-
.../JsonConverters/ResourceObjectConverter.cs | 6 +-
.../SingleOrManyDataConverterFactory.cs | 4 +-
.../WriteOnlyDocumentConverter.cs | 4 +-
.../WriteOnlyRelationshipObjectConverter.cs | 4 +-
.../Adapters/AtomicOperationObjectAdapter.cs | 12 ++--
.../Adapters/AtomicReferenceAdapter.cs | 6 +-
.../Request/Adapters/AtomicReferenceResult.cs | 4 +-
.../Request/Adapters/BaseAdapter.cs | 8 +--
.../Request/Adapters/DocumentAdapter.cs | 10 ++--
.../DocumentInOperationsRequestAdapter.cs | 8 +--
...tInResourceOrRelationshipRequestAdapter.cs | 10 ++--
.../Adapters/RelationshipDataAdapter.cs | 6 +-
.../Adapters/RequestAdapterPosition.cs | 2 +-
.../Request/Adapters/RequestAdapterState.cs | 4 +-
.../Request/Adapters/ResourceDataAdapter.cs | 12 ++--
.../ResourceDataInOperationsRequestAdapter.cs | 4 +-
.../ResourceIdentifierObjectAdapter.cs | 6 +-
.../Adapters/ResourceIdentityAdapter.cs | 20 +++----
.../Request/Adapters/ResourceObjectAdapter.cs | 10 ++--
.../Serialization/Request/JsonApiReader.cs | 8 +--
.../Request/JsonInvalidAttributeInfo.cs | 4 +-
.../Request/ModelConversionException.cs | 2 +-
.../Serialization/Response/ETagGenerator.cs | 2 +-
.../Response/FingerprintGenerator.cs | 2 +-
.../Serialization/Response/JsonApiWriter.cs | 14 ++---
.../Serialization/Response/LinkBuilder.cs | 26 ++++-----
.../Serialization/Response/MetaBuilder.cs | 8 +--
.../Response/ResourceObjectTreeNode.cs | 14 ++---
.../Response/ResponseModelAdapter.cs | 28 ++++-----
.../Services/AsyncCollectionExtensions.cs | 6 +-
.../Services/JsonApiResourceService.cs | 40 ++++++-------
.../MusicTrackReleaseDefinition.cs | 3 +-
.../CapturingDocumentAdapter.cs | 5 +-
.../EagerLoading/BuildingDefinition.cs | 3 +-
.../HitCountingResourceDefinition.cs | 3 +-
.../IsUpperCase/IsUpperCaseExpression.cs | 3 +-
.../StringLength/LengthExpression.cs | 3 +-
.../CustomFunctions/Sum/SumExpression.cs | 5 +-
.../TimeOffset/TimeOffsetExpression.cs | 3 +-
.../InjectionDbContext.cs | 3 +-
.../InjectionFakers.cs | 3 +-
.../ResourceTypeCapturingDefinition.cs | 5 +-
.../WheelSortDefinition.cs | 3 +-
.../ZeroKeys/WhiteSpaceAsKeyTests.cs | 3 +-
.../DependencyContainerRegistrationTests.cs | 7 +--
.../DefaultOperationFilterTests.cs | 3 +-
.../ResourceObjectConverterTests.cs | 7 +--
.../CapturingLoggerProvider.cs | 5 +-
test/TestBuildingBlocks/MarkedText.cs | 3 +-
.../ServiceCollectionExtensions.cs | 3 +-
.../TestBuildingBlocks/XUnitLoggerProvider.cs | 5 +-
.../ResourceConstructionExpressionTests.cs | 3 +-
239 files changed, 802 insertions(+), 907 deletions(-)
diff --git a/JsonApiDotNetCore.sln.DotSettings b/JsonApiDotNetCore.sln.DotSettings
index 7151bb82c8..0d088ac740 100644
--- a/JsonApiDotNetCore.sln.DotSettings
+++ b/JsonApiDotNetCore.sln.DotSettings
@@ -1,18 +1,7 @@

- // Use the following placeholders:
-// $EXPR$ -- source expression
-// $NAME$ -- source name (string literal or 'nameof' expression)
-// $MESSAGE$ -- string literal in the form of "$NAME$ != null"
-JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);
- 199
- 5000
- 99
- 100
- 200
- 1000
- 500
+ 5000
+ 2000
3000
- 50
False
83FF097C-C8C6-477B-9FAB-DF99B84978B5/f:ReadOnlySet.cs
SOLUTION
@@ -604,7 +593,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);
True
True
True
- Replace argument null check using throw expression with Guard clause
+ Replace argument null check using throw expression with ArgumentNullException.ThrowIfNull
True
True
False
@@ -623,13 +612,12 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);
True
CSHARP
False
- Replace argument null check with Guard clause
- JsonApiDotNetCore.ArgumentGuard.NotNull($argument$);
+ System.ArgumentNullException.ThrowIfNull($argument$);
$left$ = $right$;
$left$ = $right$ ?? throw new ArgumentNullException(nameof($argument$));
WARNING
True
- Replace argument == null check with Guard clause
+ Replace argument == null check with ArgumentNullException.ThrowIfNull
True
True
False
@@ -638,8 +626,7 @@ $left$ = $right$;
True
CSHARP
False
- Replace argument null check with Guard clause
- JsonApiDotNetCore.ArgumentGuard.NotNull($argument$);
+ System.ArgumentNullException.ThrowIfNull($argument$);
if ($argument$ == null) throw new ArgumentNullException(nameof($argument$));
WARNING
True
@@ -651,12 +638,11 @@ $left$ = $right$;
True
CSHARP
False
- Replace collection null/empty check with extension method
$collection$.IsNullOrEmpty()
$collection$ == null || !$collection$.Any()
WARNING
True
- Replace argument is null check with Guard clause
+ Replace argument is null check with ArgumentNullException.ThrowIfNull
True
True
False
@@ -665,7 +651,7 @@ $left$ = $right$;
True
CSHARP
False
- JsonApiDotNetCore.ArgumentGuard.NotNull($argument$);
+ System.ArgumentNullException.ThrowIfNull($argument$);
if ($argument$ is null) throw new ArgumentNullException(nameof($argument$));
WARNING
True
diff --git a/src/Examples/DapperExample/AtomicOperations/AmbientTransaction.cs b/src/Examples/DapperExample/AtomicOperations/AmbientTransaction.cs
index c442861bc4..11d052da66 100644
--- a/src/Examples/DapperExample/AtomicOperations/AmbientTransaction.cs
+++ b/src/Examples/DapperExample/AtomicOperations/AmbientTransaction.cs
@@ -1,5 +1,4 @@
using System.Data.Common;
-using JsonApiDotNetCore;
using JsonApiDotNetCore.AtomicOperations;
namespace DapperExample.AtomicOperations;
@@ -18,8 +17,8 @@ internal sealed class AmbientTransaction : IOperationsTransaction
public AmbientTransaction(AmbientTransactionFactory owner, DbTransaction current, Guid transactionId)
{
- ArgumentGuard.NotNull(owner);
- ArgumentGuard.NotNull(current);
+ ArgumentNullException.ThrowIfNull(owner);
+ ArgumentNullException.ThrowIfNull(current);
_owner = owner;
Current = current;
diff --git a/src/Examples/DapperExample/AtomicOperations/AmbientTransactionFactory.cs b/src/Examples/DapperExample/AtomicOperations/AmbientTransactionFactory.cs
index d10959b79a..82790819fe 100644
--- a/src/Examples/DapperExample/AtomicOperations/AmbientTransactionFactory.cs
+++ b/src/Examples/DapperExample/AtomicOperations/AmbientTransactionFactory.cs
@@ -1,6 +1,5 @@
using System.Data.Common;
using DapperExample.TranslationToSql.DataModel;
-using JsonApiDotNetCore;
using JsonApiDotNetCore.AtomicOperations;
using JsonApiDotNetCore.Configuration;
@@ -18,8 +17,8 @@ public sealed class AmbientTransactionFactory : IOperationsTransactionFactory
public AmbientTransactionFactory(IJsonApiOptions options, IDataModelService dataModelService)
{
- ArgumentGuard.NotNull(options);
- ArgumentGuard.NotNull(dataModelService);
+ ArgumentNullException.ThrowIfNull(options);
+ ArgumentNullException.ThrowIfNull(dataModelService);
_options = options;
_dataModelService = dataModelService;
@@ -64,7 +63,7 @@ async Task IOperationsTransactionFactory.BeginTransactio
internal void Detach(AmbientTransaction ambientTransaction)
{
- ArgumentGuard.NotNull(ambientTransaction);
+ ArgumentNullException.ThrowIfNull(ambientTransaction);
if (AmbientTransaction != null && AmbientTransaction == ambientTransaction)
{
diff --git a/src/Examples/DapperExample/Data/AppDbContext.cs b/src/Examples/DapperExample/Data/AppDbContext.cs
index ee18bab08e..31f09b277c 100644
--- a/src/Examples/DapperExample/Data/AppDbContext.cs
+++ b/src/Examples/DapperExample/Data/AppDbContext.cs
@@ -1,6 +1,5 @@
using DapperExample.Models;
using JetBrains.Annotations;
-using JsonApiDotNetCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
@@ -23,7 +22,7 @@ public sealed class AppDbContext : DbContext
public AppDbContext(DbContextOptions options, IConfiguration configuration)
: base(options)
{
- ArgumentGuard.NotNull(configuration);
+ ArgumentNullException.ThrowIfNull(configuration);
_configuration = configuration;
}
diff --git a/src/Examples/DapperExample/Definitions/TodoItemDefinition.cs b/src/Examples/DapperExample/Definitions/TodoItemDefinition.cs
index dc7c1802c8..be5ad02627 100644
--- a/src/Examples/DapperExample/Definitions/TodoItemDefinition.cs
+++ b/src/Examples/DapperExample/Definitions/TodoItemDefinition.cs
@@ -1,7 +1,6 @@
using System.ComponentModel;
using DapperExample.Models;
using JetBrains.Annotations;
-using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Queries.Expressions;
@@ -17,7 +16,7 @@ public sealed class TodoItemDefinition : JsonApiResourceDefinition BuildSqlCommandsForOneToOneRelationshipsChangedToNotNull(ResourceChangeDetector changeDetector,
CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(changeDetector);
+ ArgumentNullException.ThrowIfNull(changeDetector);
List sqlCommands = [];
@@ -79,7 +79,7 @@ public IReadOnlyCollection BuildSqlCommandsForOneToOneRelatio
public IReadOnlyCollection BuildSqlCommandsForChangedRelationshipsHavingForeignKeyAtRightSide(ResourceChangeDetector changeDetector,
TId leftId, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(changeDetector);
+ ArgumentNullException.ThrowIfNull(changeDetector);
List sqlCommands = [];
@@ -126,7 +126,7 @@ public IReadOnlyCollection BuildSqlCommandsForChangedRelation
public CommandDefinition BuildSqlCommandForRemoveFromToMany(RelationshipForeignKey foreignKey, object[] rightResourceIdValues,
CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(foreignKey);
+ ArgumentNullException.ThrowIfNull(foreignKey);
ArgumentGuard.NotNullNorEmpty(rightResourceIdValues);
if (!foreignKey.IsNullable)
@@ -149,8 +149,8 @@ public CommandDefinition BuildSqlCommandForRemoveFromToMany(RelationshipForeignK
public CommandDefinition BuildSqlCommandForAddToToMany(RelationshipForeignKey foreignKey, object leftId, object[] rightResourceIdValues,
CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(foreignKey);
- ArgumentGuard.NotNull(leftId);
+ ArgumentNullException.ThrowIfNull(foreignKey);
+ ArgumentNullException.ThrowIfNull(leftId);
ArgumentGuard.NotNullNorEmpty(rightResourceIdValues);
var columnsToUpdate = new Dictionary
@@ -165,7 +165,7 @@ public CommandDefinition BuildSqlCommandForAddToToMany(RelationshipForeignKey fo
public CommandDefinition BuildSqlCommandForCreate(ResourceChangeDetector changeDetector, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(changeDetector);
+ ArgumentNullException.ThrowIfNull(changeDetector);
IReadOnlyDictionary columnsToSet = changeDetector.GetChangedColumnValues();
@@ -176,7 +176,7 @@ public CommandDefinition BuildSqlCommandForCreate(ResourceChangeDetector changeD
public CommandDefinition? BuildSqlCommandForUpdate(ResourceChangeDetector changeDetector, TId leftId, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(changeDetector);
+ ArgumentNullException.ThrowIfNull(changeDetector);
IReadOnlyDictionary columnsToUpdate = changeDetector.GetChangedColumnValues();
diff --git a/src/Examples/DapperExample/Repositories/DapperRepository.cs b/src/Examples/DapperExample/Repositories/DapperRepository.cs
index 7a46e69a53..716db19519 100644
--- a/src/Examples/DapperExample/Repositories/DapperRepository.cs
+++ b/src/Examples/DapperExample/Repositories/DapperRepository.cs
@@ -114,14 +114,14 @@ public DapperRepository(ITargetedFields targetedFields, IResourceGraph resourceG
IResourceDefinitionAccessor resourceDefinitionAccessor, AmbientTransactionFactory transactionFactory, IDataModelService dataModelService,
SqlCaptureStore captureStore, ILoggerFactory loggerFactory)
{
- ArgumentGuard.NotNull(targetedFields);
- ArgumentGuard.NotNull(resourceGraph);
- ArgumentGuard.NotNull(resourceFactory);
- ArgumentGuard.NotNull(resourceDefinitionAccessor);
- ArgumentGuard.NotNull(transactionFactory);
- ArgumentGuard.NotNull(dataModelService);
- ArgumentGuard.NotNull(captureStore);
- ArgumentGuard.NotNull(loggerFactory);
+ ArgumentNullException.ThrowIfNull(targetedFields);
+ ArgumentNullException.ThrowIfNull(resourceGraph);
+ ArgumentNullException.ThrowIfNull(resourceFactory);
+ ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor);
+ ArgumentNullException.ThrowIfNull(transactionFactory);
+ ArgumentNullException.ThrowIfNull(dataModelService);
+ ArgumentNullException.ThrowIfNull(captureStore);
+ ArgumentNullException.ThrowIfNull(loggerFactory);
_targetedFields = targetedFields;
_resourceGraph = resourceGraph;
@@ -138,7 +138,7 @@ public DapperRepository(ITargetedFields targetedFields, IResourceGraph resourceG
///
public async Task> GetAsync(QueryLayer queryLayer, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(queryLayer);
+ ArgumentNullException.ThrowIfNull(queryLayer);
var mapper = new ResultSetMapper(queryLayer.Include);
@@ -180,7 +180,7 @@ public async Task CountAsync(FilterExpression? filter, CancellationToken ca
///
public Task GetForCreateAsync(Type resourceClrType, [DisallowNull] TId id, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(resourceClrType);
+ ArgumentNullException.ThrowIfNull(resourceClrType);
var resource = (TResource)_resourceFactory.CreateInstance(resourceClrType);
resource.Id = id;
@@ -191,8 +191,8 @@ public Task GetForCreateAsync(Type resourceClrType, [DisallowNull] TI
///
public async Task CreateAsync(TResource resourceFromRequest, TResource resourceForDatabase, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(resourceFromRequest);
- ArgumentGuard.NotNull(resourceForDatabase);
+ ArgumentNullException.ThrowIfNull(resourceFromRequest);
+ ArgumentNullException.ThrowIfNull(resourceForDatabase);
var changeDetector = new ResourceChangeDetector(ResourceType, _dataModelService);
@@ -283,7 +283,7 @@ await _resourceDefinitionAccessor.OnSetToManyRelationshipAsync(leftResource, has
///
public async Task GetForUpdateAsync(QueryLayer queryLayer, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(queryLayer);
+ ArgumentNullException.ThrowIfNull(queryLayer);
IReadOnlyCollection resources = await GetAsync(queryLayer, cancellationToken);
return resources.FirstOrDefault();
@@ -292,8 +292,8 @@ await _resourceDefinitionAccessor.OnSetToManyRelationshipAsync(leftResource, has
///
public async Task UpdateAsync(TResource resourceFromRequest, TResource resourceFromDatabase, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(resourceFromRequest);
- ArgumentGuard.NotNull(resourceFromDatabase);
+ ArgumentNullException.ThrowIfNull(resourceFromRequest);
+ ArgumentNullException.ThrowIfNull(resourceFromDatabase);
var changeDetector = new ResourceChangeDetector(ResourceType, _dataModelService);
changeDetector.CaptureCurrentValues(resourceFromDatabase);
@@ -384,7 +384,7 @@ await ExecuteInTransactionAsync(async transaction =>
///
public async Task SetRelationshipAsync(TResource leftResource, object? rightValue, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(leftResource);
+ ArgumentNullException.ThrowIfNull(leftResource);
RelationshipAttribute relationship = _targetedFields.Relationships.Single();
@@ -455,7 +455,7 @@ await ExecuteInTransactionAsync(async transaction =>
public async Task AddToToManyRelationshipAsync(TResource? leftResource, [DisallowNull] TId leftId, ISet rightResourceIds,
CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(rightResourceIds);
+ ArgumentNullException.ThrowIfNull(rightResourceIds);
var relationship = (HasManyAttribute)_targetedFields.Relationships.Single();
@@ -495,8 +495,8 @@ await ExecuteInTransactionAsync(async transaction =>
///
public async Task RemoveFromToManyRelationshipAsync(TResource leftResource, ISet rightResourceIds, CancellationToken cancellationToken)
{
- ArgumentGuard.NotNull(leftResource);
- ArgumentGuard.NotNull(rightResourceIds);
+ ArgumentNullException.ThrowIfNull(leftResource);
+ ArgumentNullException.ThrowIfNull(rightResourceIds);
var relationship = (HasManyAttribute)_targetedFields.Relationships.Single();
diff --git a/src/Examples/DapperExample/Repositories/ResourceChangeDetector.cs b/src/Examples/DapperExample/Repositories/ResourceChangeDetector.cs
index 73213445e2..58f7579254 100644
--- a/src/Examples/DapperExample/Repositories/ResourceChangeDetector.cs
+++ b/src/Examples/DapperExample/Repositories/ResourceChangeDetector.cs
@@ -24,8 +24,8 @@ internal sealed class ResourceChangeDetector
public ResourceChangeDetector(ResourceType resourceType, IDataModelService dataModelService)
{
- ArgumentGuard.NotNull(resourceType);
- ArgumentGuard.NotNull(dataModelService);
+ ArgumentNullException.ThrowIfNull(resourceType);
+ ArgumentNullException.ThrowIfNull(dataModelService);
ResourceType = resourceType;
_dataModelService = dataModelService;
@@ -33,7 +33,7 @@ public ResourceChangeDetector(ResourceType resourceType, IDataModelService dataM
public void CaptureCurrentValues(IIdentifiable resource)
{
- ArgumentGuard.NotNull(resource);
+ ArgumentNullException.ThrowIfNull(resource);
AssertSameType(ResourceType, resource);
_currentColumnValues = CaptureColumnValues(resource);
@@ -42,7 +42,7 @@ public void CaptureCurrentValues(IIdentifiable resource)
public void CaptureNewValues(IIdentifiable resource)
{
- ArgumentGuard.NotNull(resource);
+ ArgumentNullException.ThrowIfNull(resource);
AssertSameType(ResourceType, resource);
_newColumnValues = CaptureColumnValues(resource);
diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/DeleteOneToOneStatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/DeleteOneToOneStatementBuilder.cs
index 24be003a0a..afd955dc62 100644
--- a/src/Examples/DapperExample/TranslationToSql/Builders/DeleteOneToOneStatementBuilder.cs
+++ b/src/Examples/DapperExample/TranslationToSql/Builders/DeleteOneToOneStatementBuilder.cs
@@ -1,6 +1,5 @@
using DapperExample.TranslationToSql.DataModel;
using DapperExample.TranslationToSql.TreeNodes;
-using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Queries.Expressions;
@@ -11,8 +10,8 @@ internal sealed class DeleteOneToOneStatementBuilder(IDataModelService dataModel
{
public DeleteNode Build(ResourceType resourceType, string whereColumnName, object? whereValue)
{
- ArgumentGuard.NotNull(resourceType);
- ArgumentGuard.NotNullNorEmpty(whereColumnName);
+ ArgumentNullException.ThrowIfNull(resourceType);
+ ArgumentException.ThrowIfNullOrEmpty(whereColumnName);
ResetState();
diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/DeleteResourceStatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/DeleteResourceStatementBuilder.cs
index 2e4779e334..b3afe4a2a4 100644
--- a/src/Examples/DapperExample/TranslationToSql/Builders/DeleteResourceStatementBuilder.cs
+++ b/src/Examples/DapperExample/TranslationToSql/Builders/DeleteResourceStatementBuilder.cs
@@ -12,7 +12,7 @@ internal sealed class DeleteResourceStatementBuilder(IDataModelService dataModel
{
public DeleteNode Build(ResourceType resourceType, params object[] idValues)
{
- ArgumentGuard.NotNull(resourceType);
+ ArgumentNullException.ThrowIfNull(resourceType);
ArgumentGuard.NotNullNorEmpty(idValues);
ResetState();
diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/InsertStatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/InsertStatementBuilder.cs
index 7a12ec5acd..2f71cee112 100644
--- a/src/Examples/DapperExample/TranslationToSql/Builders/InsertStatementBuilder.cs
+++ b/src/Examples/DapperExample/TranslationToSql/Builders/InsertStatementBuilder.cs
@@ -1,7 +1,6 @@
using System.Collections.ObjectModel;
using DapperExample.TranslationToSql.DataModel;
using DapperExample.TranslationToSql.TreeNodes;
-using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Resources;
@@ -12,8 +11,8 @@ internal sealed class InsertStatementBuilder(IDataModelService dataModelService)
{
public InsertNode Build(ResourceType resourceType, IReadOnlyDictionary columnsToSet)
{
- ArgumentGuard.NotNull(resourceType);
- ArgumentGuard.NotNull(columnsToSet);
+ ArgumentNullException.ThrowIfNull(resourceType);
+ ArgumentNullException.ThrowIfNull(columnsToSet);
ResetState();
diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/SelectStatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/SelectStatementBuilder.cs
index 95a2681a80..23a2b7d2d0 100644
--- a/src/Examples/DapperExample/TranslationToSql/Builders/SelectStatementBuilder.cs
+++ b/src/Examples/DapperExample/TranslationToSql/Builders/SelectStatementBuilder.cs
@@ -4,7 +4,6 @@
using DapperExample.TranslationToSql.Generators;
using DapperExample.TranslationToSql.Transformations;
using DapperExample.TranslationToSql.TreeNodes;
-using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Errors;
using JsonApiDotNetCore.Queries;
@@ -50,7 +49,7 @@ private SelectStatementBuilder(QueryState queryState)
public SelectNode Build(QueryLayer queryLayer, SelectShape selectShape)
{
- ArgumentGuard.NotNull(queryLayer);
+ ArgumentNullException.ThrowIfNull(queryLayer);
// Convert queryLayer.Include into multiple levels of queryLayer.Selection.
var includeConverter = new QueryLayerIncludeConverter(queryLayer);
@@ -701,7 +700,7 @@ private sealed class NullableAttributeFinder : QueryExpressionRewriter