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 public NullableAttributeFinder(IDataModelService dataModelService) { - ArgumentGuard.NotNull(dataModelService); + ArgumentNullException.ThrowIfNull(dataModelService); _dataModelService = dataModelService; } @@ -758,10 +757,10 @@ private sealed class QueryState public QueryState(IDataModelService dataModelService, TableAliasGenerator tableAliasGenerator, ParameterGenerator parameterGenerator, ILoggerFactory loggerFactory) { - ArgumentGuard.NotNull(dataModelService); - ArgumentGuard.NotNull(tableAliasGenerator); - ArgumentGuard.NotNull(parameterGenerator); - ArgumentGuard.NotNull(loggerFactory); + ArgumentNullException.ThrowIfNull(dataModelService); + ArgumentNullException.ThrowIfNull(tableAliasGenerator); + ArgumentNullException.ThrowIfNull(parameterGenerator); + ArgumentNullException.ThrowIfNull(loggerFactory); DataModelService = dataModelService; TableAliasGenerator = tableAliasGenerator; diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/SqlQueryBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/SqlQueryBuilder.cs index e8cb8f894a..d94eca2f0d 100644 --- a/src/Examples/DapperExample/TranslationToSql/Builders/SqlQueryBuilder.cs +++ b/src/Examples/DapperExample/TranslationToSql/Builders/SqlQueryBuilder.cs @@ -1,6 +1,5 @@ using System.Text; using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace DapperExample.TranslationToSql.Builders; @@ -37,7 +36,7 @@ internal sealed class SqlQueryBuilder(DatabaseProvider databaseProvider) : SqlTr public string GetCommand(SqlTreeNode node) { - ArgumentGuard.NotNull(node); + ArgumentNullException.ThrowIfNull(node); ResetState(); diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/StatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/StatementBuilder.cs index 06ebc1867f..de35ea5ba9 100644 --- a/src/Examples/DapperExample/TranslationToSql/Builders/StatementBuilder.cs +++ b/src/Examples/DapperExample/TranslationToSql/Builders/StatementBuilder.cs @@ -1,7 +1,6 @@ using DapperExample.TranslationToSql.DataModel; using DapperExample.TranslationToSql.Generators; using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Resources.Annotations; @@ -15,7 +14,7 @@ internal abstract class StatementBuilder protected StatementBuilder(IDataModelService dataModelService) { - ArgumentGuard.NotNull(dataModelService); + ArgumentNullException.ThrowIfNull(dataModelService); _dataModelService = dataModelService; } diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/UpdateClearOneToOneStatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/UpdateClearOneToOneStatementBuilder.cs index 6a8c33a4e0..610ae9830d 100644 --- a/src/Examples/DapperExample/TranslationToSql/Builders/UpdateClearOneToOneStatementBuilder.cs +++ b/src/Examples/DapperExample/TranslationToSql/Builders/UpdateClearOneToOneStatementBuilder.cs @@ -1,6 +1,5 @@ using DapperExample.TranslationToSql.DataModel; using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Queries.Expressions; @@ -11,9 +10,9 @@ internal sealed class UpdateClearOneToOneStatementBuilder(IDataModelService data { public UpdateNode Build(ResourceType resourceType, string setColumnName, string whereColumnName, object? whereValue) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNullNorEmpty(setColumnName); - ArgumentGuard.NotNullNorEmpty(whereColumnName); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentException.ThrowIfNullOrEmpty(setColumnName); + ArgumentException.ThrowIfNullOrEmpty(whereColumnName); ResetState(); diff --git a/src/Examples/DapperExample/TranslationToSql/Builders/UpdateResourceStatementBuilder.cs b/src/Examples/DapperExample/TranslationToSql/Builders/UpdateResourceStatementBuilder.cs index a745747a61..619dba7797 100644 --- a/src/Examples/DapperExample/TranslationToSql/Builders/UpdateResourceStatementBuilder.cs +++ b/src/Examples/DapperExample/TranslationToSql/Builders/UpdateResourceStatementBuilder.cs @@ -12,7 +12,7 @@ internal sealed class UpdateResourceStatementBuilder(IDataModelService dataModel { public UpdateNode Build(ResourceType resourceType, IReadOnlyDictionary columnsToUpdate, params object[] idValues) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); ArgumentGuard.NotNullNorEmpty(columnsToUpdate); ArgumentGuard.NotNullNorEmpty(idValues); diff --git a/src/Examples/DapperExample/TranslationToSql/DataModel/BaseDataModelService.cs b/src/Examples/DapperExample/TranslationToSql/DataModel/BaseDataModelService.cs index 235e3e72d5..3c752ffcbd 100644 --- a/src/Examples/DapperExample/TranslationToSql/DataModel/BaseDataModelService.cs +++ b/src/Examples/DapperExample/TranslationToSql/DataModel/BaseDataModelService.cs @@ -5,7 +5,6 @@ using System.Reflection; using Dapper; using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Resources; using JsonApiDotNetCore.Resources.Annotations; @@ -25,7 +24,7 @@ public abstract class BaseDataModelService : IDataModelService protected BaseDataModelService(IResourceGraph resourceGraph) { - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(resourceGraph); ResourceGraph = resourceGraph; } @@ -114,10 +113,10 @@ private static bool IsMapped(PropertyInfo property) public object? GetColumnValue(ResourceType resourceType, IIdentifiable resource, string columnName) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(resource); AssertSameType(resourceType, resource); - ArgumentGuard.NotNullNorEmpty(columnName); + ArgumentException.ThrowIfNullOrEmpty(columnName); IReadOnlyDictionary columnMappings = GetColumnMappings(resourceType); diff --git a/src/Examples/DapperExample/TranslationToSql/DataModel/RelationshipForeignKey.cs b/src/Examples/DapperExample/TranslationToSql/DataModel/RelationshipForeignKey.cs index 6f5572001a..94633a9c36 100644 --- a/src/Examples/DapperExample/TranslationToSql/DataModel/RelationshipForeignKey.cs +++ b/src/Examples/DapperExample/TranslationToSql/DataModel/RelationshipForeignKey.cs @@ -2,7 +2,6 @@ using DapperExample.TranslationToSql.Builders; using Humanizer; using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Resources.Annotations; @@ -38,8 +37,8 @@ public sealed class RelationshipForeignKey public RelationshipForeignKey(DatabaseProvider databaseProvider, RelationshipAttribute relationship, bool isAtLeftSide, string columnName, bool isNullable) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNullNorEmpty(columnName); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentException.ThrowIfNullOrEmpty(columnName); _databaseProvider = databaseProvider; Relationship = relationship; diff --git a/src/Examples/DapperExample/TranslationToSql/Generators/UniqueNameGenerator.cs b/src/Examples/DapperExample/TranslationToSql/Generators/UniqueNameGenerator.cs index 3ea42ab529..5254f4a024 100644 --- a/src/Examples/DapperExample/TranslationToSql/Generators/UniqueNameGenerator.cs +++ b/src/Examples/DapperExample/TranslationToSql/Generators/UniqueNameGenerator.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.Generators; internal abstract class UniqueNameGenerator @@ -9,7 +7,7 @@ internal abstract class UniqueNameGenerator protected UniqueNameGenerator(string prefix) { - ArgumentGuard.NotNullNorEmpty(prefix); + ArgumentException.ThrowIfNullOrEmpty(prefix); _prefix = prefix; } diff --git a/src/Examples/DapperExample/TranslationToSql/SqlCommand.cs b/src/Examples/DapperExample/TranslationToSql/SqlCommand.cs index 37ed2d3ea5..735da0a55f 100644 --- a/src/Examples/DapperExample/TranslationToSql/SqlCommand.cs +++ b/src/Examples/DapperExample/TranslationToSql/SqlCommand.cs @@ -1,5 +1,4 @@ using JetBrains.Annotations; -using JsonApiDotNetCore; namespace DapperExample.TranslationToSql; @@ -14,8 +13,8 @@ public sealed class SqlCommand internal SqlCommand(string statement, IDictionary parameters) { - ArgumentGuard.NotNull(statement); - ArgumentGuard.NotNull(parameters); + ArgumentNullException.ThrowIfNull(statement); + ArgumentNullException.ThrowIfNull(parameters); Statement = statement; Parameters = parameters; diff --git a/src/Examples/DapperExample/TranslationToSql/Transformations/ColumnSelectorUsageCollector.cs b/src/Examples/DapperExample/TranslationToSql/Transformations/ColumnSelectorUsageCollector.cs index d218093936..e7c7799700 100644 --- a/src/Examples/DapperExample/TranslationToSql/Transformations/ColumnSelectorUsageCollector.cs +++ b/src/Examples/DapperExample/TranslationToSql/Transformations/ColumnSelectorUsageCollector.cs @@ -1,5 +1,4 @@ using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; namespace DapperExample.TranslationToSql.Transformations; @@ -15,14 +14,14 @@ internal sealed partial class ColumnSelectorUsageCollector : SqlTreeNodeVisitor< public ColumnSelectorUsageCollector(ILoggerFactory loggerFactory) { - ArgumentGuard.NotNull(loggerFactory); + ArgumentNullException.ThrowIfNull(loggerFactory); _logger = loggerFactory.CreateLogger(); } public void Collect(SelectNode select) { - ArgumentGuard.NotNull(select); + ArgumentNullException.ThrowIfNull(select); LogStarted(); diff --git a/src/Examples/DapperExample/TranslationToSql/Transformations/StaleColumnReferenceRewriter.cs b/src/Examples/DapperExample/TranslationToSql/Transformations/StaleColumnReferenceRewriter.cs index 6f42345ee1..e364203684 100644 --- a/src/Examples/DapperExample/TranslationToSql/Transformations/StaleColumnReferenceRewriter.cs +++ b/src/Examples/DapperExample/TranslationToSql/Transformations/StaleColumnReferenceRewriter.cs @@ -1,7 +1,6 @@ using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; namespace DapperExample.TranslationToSql.Transformations; @@ -37,8 +36,8 @@ internal sealed partial class StaleColumnReferenceRewriter : SqlTreeNodeVisitor< public StaleColumnReferenceRewriter(IReadOnlyDictionary oldToNewTableAliasMap, ILoggerFactory loggerFactory) { - ArgumentGuard.NotNull(oldToNewTableAliasMap); - ArgumentGuard.NotNull(loggerFactory); + ArgumentNullException.ThrowIfNull(oldToNewTableAliasMap); + ArgumentNullException.ThrowIfNull(loggerFactory); _oldToNewTableAliasMap = oldToNewTableAliasMap; _logger = loggerFactory.CreateLogger(); diff --git a/src/Examples/DapperExample/TranslationToSql/Transformations/UnusedSelectorsRewriter.cs b/src/Examples/DapperExample/TranslationToSql/Transformations/UnusedSelectorsRewriter.cs index 08f09da99a..fe0f326209 100644 --- a/src/Examples/DapperExample/TranslationToSql/Transformations/UnusedSelectorsRewriter.cs +++ b/src/Examples/DapperExample/TranslationToSql/Transformations/UnusedSelectorsRewriter.cs @@ -1,7 +1,6 @@ using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using DapperExample.TranslationToSql.TreeNodes; -using JsonApiDotNetCore; namespace DapperExample.TranslationToSql.Transformations; @@ -36,7 +35,7 @@ internal sealed partial class UnusedSelectorsRewriter : SqlTreeNodeVisitor(); @@ -44,7 +43,7 @@ public UnusedSelectorsRewriter(ILoggerFactory loggerFactory) public SelectNode RemoveUnusedSelectorsInSubQueries(SelectNode select) { - ArgumentGuard.NotNull(select); + ArgumentNullException.ThrowIfNull(select); _rootSelect = select; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnAssignmentNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnAssignmentNode.cs index 1884dc8dbf..3578ea9a55 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnAssignmentNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnAssignmentNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -17,8 +15,8 @@ internal sealed class ColumnAssignmentNode : SqlTreeNode public ColumnAssignmentNode(ColumnNode column, SqlValueNode value) { - ArgumentGuard.NotNull(column); - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(column); + ArgumentNullException.ThrowIfNull(value); Column = column; Value = value; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnInSelectNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnInSelectNode.cs index 88625104d2..14d82bb1d3 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnInSelectNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnInSelectNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -19,7 +17,7 @@ internal sealed class ColumnInSelectNode(ColumnSelectorNode selector, string? ta private static string GetColumnName(ColumnSelectorNode selector) { - ArgumentGuard.NotNull(selector); + ArgumentNullException.ThrowIfNull(selector); return selector.Identity; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnNode.cs index e4fbcf14e6..da348882a9 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -13,7 +11,7 @@ internal abstract class ColumnNode : SqlValueNode protected ColumnNode(string name, ColumnType type, string? tableAlias) { - ArgumentGuard.NotNullNorEmpty(name); + ArgumentException.ThrowIfNullOrEmpty(name); Name = name; Type = type; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnSelectorNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnSelectorNode.cs index ab2ab1031f..6c8bb9e36a 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnSelectorNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ColumnSelectorNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -19,7 +17,7 @@ internal sealed class ColumnSelectorNode : SelectorNode public ColumnSelectorNode(ColumnNode column, string? alias) : base(alias) { - ArgumentGuard.NotNull(column); + ArgumentNullException.ThrowIfNull(column); Column = column; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ComparisonNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ComparisonNode.cs index dbf61d5451..7264189a6d 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ComparisonNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ComparisonNode.cs @@ -1,4 +1,3 @@ -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace DapperExample.TranslationToSql.TreeNodes; @@ -16,8 +15,8 @@ internal sealed class ComparisonNode : FilterNode public ComparisonNode(ComparisonOperator @operator, SqlValueNode left, SqlValueNode right) { - ArgumentGuard.NotNull(left); - ArgumentGuard.NotNull(right); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); Operator = @operator; Left = left; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/CountNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/CountNode.cs index 07182d036f..9133969961 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/CountNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/CountNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -16,7 +14,7 @@ internal sealed class CountNode : SqlValueNode public CountNode(SelectNode subSelect) { - ArgumentGuard.NotNull(subSelect); + ArgumentNullException.ThrowIfNull(subSelect); SubSelect = subSelect; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/DeleteNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/DeleteNode.cs index aa3968f872..512e0e7321 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/DeleteNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/DeleteNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -14,8 +12,8 @@ internal sealed class DeleteNode : SqlTreeNode public DeleteNode(TableNode table, WhereNode where) { - ArgumentGuard.NotNull(table); - ArgumentGuard.NotNull(where); + ArgumentNullException.ThrowIfNull(table); + ArgumentNullException.ThrowIfNull(where); Table = table; Where = where; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ExistsNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ExistsNode.cs index b73882122c..96087886f9 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ExistsNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ExistsNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -16,7 +14,7 @@ internal sealed class ExistsNode : FilterNode public ExistsNode(SelectNode subSelect) { - ArgumentGuard.NotNull(subSelect); + ArgumentNullException.ThrowIfNull(subSelect); SubSelect = subSelect; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/InNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/InNode.cs index 26d3c2ec47..114a141eaa 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/InNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/InNode.cs @@ -14,7 +14,7 @@ internal sealed class InNode : FilterNode public InNode(ColumnNode column, IReadOnlyList values) { - ArgumentGuard.NotNull(column); + ArgumentNullException.ThrowIfNull(column); ArgumentGuard.NotNullNorEmpty(values); Column = column; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/InsertNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/InsertNode.cs index 8ed6770136..f85857f677 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/InsertNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/InsertNode.cs @@ -14,7 +14,7 @@ internal sealed class InsertNode : SqlTreeNode public InsertNode(TableNode table, IReadOnlyCollection assignments) { - ArgumentGuard.NotNull(table); + ArgumentNullException.ThrowIfNull(table); ArgumentGuard.NotNullNorEmpty(assignments); Table = table; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/JoinNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/JoinNode.cs index 6ed2e4c73c..48140a0c04 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/JoinNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/JoinNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -16,8 +14,8 @@ internal sealed class JoinNode : TableAccessorNode public JoinNode(JoinType joinType, TableSourceNode source, ColumnNode outerColumn, ColumnNode innerColumn) : base(source) { - ArgumentGuard.NotNull(outerColumn); - ArgumentGuard.NotNull(innerColumn); + ArgumentNullException.ThrowIfNull(outerColumn); + ArgumentNullException.ThrowIfNull(innerColumn); JoinType = joinType; OuterColumn = outerColumn; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/LikeNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/LikeNode.cs index 034e5c012e..f713e687fc 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/LikeNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/LikeNode.cs @@ -1,4 +1,3 @@ -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace DapperExample.TranslationToSql.TreeNodes; @@ -16,8 +15,8 @@ internal sealed class LikeNode : FilterNode public LikeNode(ColumnNode column, TextMatchKind matchKind, string text) { - ArgumentGuard.NotNull(column); - ArgumentGuard.NotNull(text); + ArgumentNullException.ThrowIfNull(column); + ArgumentNullException.ThrowIfNull(text); Column = column; MatchKind = matchKind; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/LogicalNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/LogicalNode.cs index a01306d061..ebf0554167 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/LogicalNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/LogicalNode.cs @@ -1,4 +1,3 @@ -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace DapperExample.TranslationToSql.TreeNodes; @@ -20,7 +19,7 @@ public LogicalNode(LogicalOperator @operator, params FilterNode[] terms) public LogicalNode(LogicalOperator @operator, IReadOnlyList terms) { - ArgumentGuard.NotNull(terms); + ArgumentNullException.ThrowIfNull(terms); if (terms.Count < 2) { diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/NotNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/NotNode.cs index 38c5d80f26..f1f2e9ed22 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/NotNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/NotNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -13,7 +11,7 @@ internal sealed class NotNode : FilterNode public NotNode(FilterNode child) { - ArgumentGuard.NotNull(child); + ArgumentNullException.ThrowIfNull(child); Child = child; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByColumnNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByColumnNode.cs index 372b1e86ff..a62094ae5b 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByColumnNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByColumnNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -17,7 +15,7 @@ internal sealed class OrderByColumnNode : OrderByTermNode public OrderByColumnNode(ColumnNode column, bool isAscending) : base(isAscending) { - ArgumentGuard.NotNull(column); + ArgumentNullException.ThrowIfNull(column); Column = column; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByCountNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByCountNode.cs index 3d8f8c240a..c044d98ba9 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByCountNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/OrderByCountNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -17,7 +15,7 @@ internal sealed class OrderByCountNode : OrderByTermNode public OrderByCountNode(CountNode count, bool isAscending) : base(isAscending) { - ArgumentGuard.NotNull(count); + ArgumentNullException.ThrowIfNull(count); Count = count; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ParameterNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ParameterNode.cs index a9feaa7836..6e206fa04d 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/ParameterNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/ParameterNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -16,7 +14,7 @@ internal sealed class ParameterNode : SqlValueNode public ParameterNode(string name, object? value) { - ArgumentGuard.NotNullNorEmpty(name); + ArgumentException.ThrowIfNullOrEmpty(name); if (!name.StartsWith('@') || name.Length < 2) { diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableAccessorNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableAccessorNode.cs index 4096789919..2822749230 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableAccessorNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableAccessorNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -11,7 +9,7 @@ internal abstract class TableAccessorNode : SqlTreeNode protected TableAccessorNode(TableSourceNode source) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); Source = source; } diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableNode.cs index 6abb913418..9fca1971cb 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/TableNode.cs @@ -1,5 +1,4 @@ using Humanizer; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Resources.Annotations; @@ -26,8 +25,8 @@ internal sealed class TableNode : TableSourceNode public TableNode(ResourceType resourceType, IReadOnlyDictionary columnMappings, string? alias) : base(alias) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(columnMappings); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(columnMappings); _resourceType = resourceType; _columnMappings = columnMappings; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/UpdateNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/UpdateNode.cs index 3aa5dbdf73..7f9b1b79a4 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/UpdateNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/UpdateNode.cs @@ -15,9 +15,9 @@ internal sealed class UpdateNode : SqlTreeNode public UpdateNode(TableNode table, IReadOnlyCollection assignments, WhereNode where) { - ArgumentGuard.NotNull(table); + ArgumentNullException.ThrowIfNull(table); ArgumentGuard.NotNullNorEmpty(assignments); - ArgumentGuard.NotNull(where); + ArgumentNullException.ThrowIfNull(where); Table = table; Assignments = assignments; diff --git a/src/Examples/DapperExample/TranslationToSql/TreeNodes/WhereNode.cs b/src/Examples/DapperExample/TranslationToSql/TreeNodes/WhereNode.cs index d8d72601c5..4e8c4d54e8 100644 --- a/src/Examples/DapperExample/TranslationToSql/TreeNodes/WhereNode.cs +++ b/src/Examples/DapperExample/TranslationToSql/TreeNodes/WhereNode.cs @@ -1,5 +1,3 @@ -using JsonApiDotNetCore; - namespace DapperExample.TranslationToSql.TreeNodes; /// @@ -13,7 +11,7 @@ internal sealed class WhereNode : SqlTreeNode public WhereNode(FilterNode filter) { - ArgumentGuard.NotNull(filter); + ArgumentNullException.ThrowIfNull(filter); Filter = filter; } diff --git a/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs b/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs index 137654fb3e..1eea1c3841 100644 --- a/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs +++ b/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs @@ -9,13 +9,6 @@ namespace JsonApiDotNetCore; internal static class ArgumentGuard { - [AssertionMethod] - public static void NotNull([NoEnumeration] [SysNotNull] T? value, [CallerArgumentExpression(nameof(value))] string? parameterName = null) - where T : class - { - ArgumentNullException.ThrowIfNull(value, parameterName); - } - [AssertionMethod] public static void NotNullNorEmpty([SysNotNull] IEnumerable? value, [CallerArgumentExpression(nameof(value))] string? parameterName = null) { @@ -26,16 +19,4 @@ public static void NotNullNorEmpty([SysNotNull] IEnumerable? value, [Calle throw new ArgumentException("Collection cannot be null or empty.", parameterName); } } - - [AssertionMethod] - public static void NotNullNorEmpty([SysNotNull] string? value, [CallerArgumentExpression(nameof(value))] string? parameterName = null) - { - ArgumentException.ThrowIfNullOrEmpty(value, parameterName); - } - - [AssertionMethod] - public static void NotNullNorWhitespace([SysNotNull] string? value, [CallerArgumentExpression(nameof(value))] string? parameterName = null) - { - ArgumentException.ThrowIfNullOrWhiteSpace(value, parameterName); - } } diff --git a/src/JsonApiDotNetCore.Annotations/CollectionConverter.cs b/src/JsonApiDotNetCore.Annotations/CollectionConverter.cs index f055c6548f..cbf834b630 100644 --- a/src/JsonApiDotNetCore.Annotations/CollectionConverter.cs +++ b/src/JsonApiDotNetCore.Annotations/CollectionConverter.cs @@ -36,8 +36,8 @@ private CollectionConverter() /// public IEnumerable CopyToTypedCollection(IEnumerable source, Type collectionType) { - ArgumentGuard.NotNull(source); - ArgumentGuard.NotNull(collectionType); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(collectionType); Type concreteCollectionType = ToConcreteCollectionType(collectionType); dynamic concreteCollectionInstance = Activator.CreateInstance(concreteCollectionType)!; @@ -125,7 +125,7 @@ public IReadOnlyCollection ExtractResources(object? value) /// public bool TypeCanContainHashSet(Type collectionType) { - ArgumentGuard.NotNull(collectionType); + ArgumentNullException.ThrowIfNull(collectionType); if (collectionType.IsGenericType) { diff --git a/src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs b/src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs index 07817698e0..3cda945d74 100644 --- a/src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs +++ b/src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs @@ -111,9 +111,9 @@ public ResourceType(string publicName, ClientIdGenerationMode? clientIdGeneratio IReadOnlyCollection? eagerLoads, LinkTypes topLevelLinks = LinkTypes.NotConfigured, LinkTypes resourceLinks = LinkTypes.NotConfigured, LinkTypes relationshipLinks = LinkTypes.NotConfigured) { - ArgumentGuard.NotNullNorWhitespace(publicName); - ArgumentGuard.NotNull(clrType); - ArgumentGuard.NotNull(identityClrType); + ArgumentException.ThrowIfNullOrWhiteSpace(publicName); + ArgumentNullException.ThrowIfNull(clrType); + ArgumentNullException.ThrowIfNull(identityClrType); PublicName = publicName; ClientIdGeneration = clientIdGeneration; @@ -165,7 +165,7 @@ public AttrAttribute GetAttributeByPublicName(string publicName) public AttrAttribute? FindAttributeByPublicName(string publicName) { - ArgumentGuard.NotNull(publicName); + ArgumentNullException.ThrowIfNull(publicName); return _fieldsByPublicName.TryGetValue(publicName, out ResourceFieldAttribute? field) && field is AttrAttribute attribute ? attribute : null; } @@ -179,7 +179,7 @@ public AttrAttribute GetAttributeByPropertyName(string propertyName) public AttrAttribute? FindAttributeByPropertyName(string propertyName) { - ArgumentGuard.NotNull(propertyName); + ArgumentNullException.ThrowIfNull(propertyName); return _fieldsByPropertyName.TryGetValue(propertyName, out ResourceFieldAttribute? field) && field is AttrAttribute attribute ? attribute : null; } @@ -192,7 +192,7 @@ public RelationshipAttribute GetRelationshipByPublicName(string publicName) public RelationshipAttribute? FindRelationshipByPublicName(string publicName) { - ArgumentGuard.NotNull(publicName); + ArgumentNullException.ThrowIfNull(publicName); return _fieldsByPublicName.TryGetValue(publicName, out ResourceFieldAttribute? field) && field is RelationshipAttribute relationship ? relationship @@ -209,7 +209,7 @@ public RelationshipAttribute GetRelationshipByPropertyName(string propertyName) public RelationshipAttribute? FindRelationshipByPropertyName(string propertyName) { - ArgumentGuard.NotNull(propertyName); + ArgumentNullException.ThrowIfNull(propertyName); return _fieldsByPropertyName.TryGetValue(propertyName, out ResourceFieldAttribute? field) && field is RelationshipAttribute relationship ? relationship @@ -229,7 +229,7 @@ public IReadOnlySet GetAllConcreteDerivedTypes() /// public ResourceType GetTypeOrDerived(Type clrType) { - ArgumentGuard.NotNull(clrType); + ArgumentNullException.ThrowIfNull(clrType); ResourceType? derivedType = FindTypeOrDerived(this, clrType); diff --git a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasManyAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasManyAttribute.cs index 274a6bb16f..a906f4a667 100644 --- a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasManyAttribute.cs +++ b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasManyAttribute.cs @@ -69,7 +69,7 @@ private bool EvaluateIsManyToMany() /// public override void SetValue(object resource, object? newValue) { - ArgumentGuard.NotNull(newValue); + ArgumentNullException.ThrowIfNull(newValue); AssertIsIdentifiableCollection(newValue); base.SetValue(resource, newValue); @@ -99,8 +99,8 @@ private void AssertIsIdentifiableCollection(object newValue) /// public void AddValue(object resource, IIdentifiable resourceToAdd) { - ArgumentGuard.NotNull(resource); - ArgumentGuard.NotNull(resourceToAdd); + ArgumentNullException.ThrowIfNull(resource); + ArgumentNullException.ThrowIfNull(resourceToAdd); object? rightValue = GetValue(resource); List rightResources = CollectionConverter.Instance.ExtractResources(rightValue).ToList(); diff --git a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs index 72bdecf7b0..21d5bfab1d 100644 --- a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs +++ b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs @@ -59,7 +59,7 @@ public ResourceType RightType get => _rightType!; internal set { - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(value); _rightType = value; } } diff --git a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs index 3b55c4b644..593b0a905d 100644 --- a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs +++ b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs @@ -43,7 +43,7 @@ public PropertyInfo Property get => _property!; internal set { - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(value); _property = value; } } @@ -56,7 +56,7 @@ public ResourceType Type get => _type!; internal set { - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(value); _type = value; } } @@ -67,7 +67,7 @@ internal set /// public object? GetValue(object resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); AssertIsIdentifiable(resource); if (Property.GetMethod == null) @@ -93,7 +93,7 @@ internal set /// public virtual void SetValue(object resource, object? newValue) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); AssertIsIdentifiable(resource); if (Property.SetMethod == null) diff --git a/src/JsonApiDotNetCore.Annotations/Resources/RuntimeTypeConverter.cs b/src/JsonApiDotNetCore.Annotations/Resources/RuntimeTypeConverter.cs index a811dd0646..74a4eb877c 100644 --- a/src/JsonApiDotNetCore.Annotations/Resources/RuntimeTypeConverter.cs +++ b/src/JsonApiDotNetCore.Annotations/Resources/RuntimeTypeConverter.cs @@ -33,7 +33,7 @@ public static class RuntimeTypeConverter /// public static object? ConvertType(object? value, Type type) { - ArgumentGuard.NotNull(type); + ArgumentNullException.ThrowIfNull(type); // Earlier versions of JsonApiDotNetCore failed to pass CultureInfo.InvariantCulture in the parsing below, which resulted in the 'current' // culture being used. Unlike parsing JSON request/response bodies, this effectively meant that query strings were parsed based on the @@ -140,7 +140,7 @@ public static class RuntimeTypeConverter /// public static bool CanContainNull(Type type) { - ArgumentGuard.NotNull(type); + ArgumentNullException.ThrowIfNull(type); return !type.IsValueType || Nullable.GetUnderlyingType(type) != null; } @@ -153,7 +153,7 @@ public static bool CanContainNull(Type type) /// public static object? GetDefaultValue(Type type) { - ArgumentGuard.NotNull(type); + ArgumentNullException.ThrowIfNull(type); return type.IsValueType ? DefaultTypeCache.GetOrAdd(type, Activator.CreateInstance) : null; } diff --git a/src/JsonApiDotNetCore.Annotations/TypeExtensions.cs b/src/JsonApiDotNetCore.Annotations/TypeExtensions.cs index 785dff030a..89b8158554 100644 --- a/src/JsonApiDotNetCore.Annotations/TypeExtensions.cs +++ b/src/JsonApiDotNetCore.Annotations/TypeExtensions.cs @@ -15,7 +15,7 @@ public static bool IsOrImplementsInterface(this Type? source) /// private static bool IsOrImplementsInterface(this Type? source, Type interfaceType) { - ArgumentGuard.NotNull(interfaceType); + ArgumentNullException.ThrowIfNull(interfaceType); if (source == null) { @@ -41,7 +41,7 @@ private static bool AreTypesEqual(Type left, Type right, bool isLeftGeneric) /// public static string GetFriendlyTypeName(this Type type) { - ArgumentGuard.NotNull(type); + ArgumentNullException.ThrowIfNull(type); // Based on https://stackoverflow.com/questions/2581642/how-do-i-get-the-type-name-of-a-generic-type-argument. diff --git a/src/JsonApiDotNetCore/AtomicOperations/DefaultOperationFilter.cs b/src/JsonApiDotNetCore/AtomicOperations/DefaultOperationFilter.cs index 1407674150..fb632dd276 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/DefaultOperationFilter.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/DefaultOperationFilter.cs @@ -12,7 +12,7 @@ public class DefaultOperationFilter : IAtomicOperationFilter /// public virtual bool IsEnabled(ResourceType resourceType, WriteOperationKind writeOperation) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); // To match the behavior of non-operations controllers: // If an operation is enabled on a base type, it is implicitly enabled on all derived types. @@ -34,7 +34,7 @@ public virtual bool IsEnabled(ResourceType resourceType, WriteOperationKind writ protected virtual JsonApiEndpoints? GetJsonApiEndpoints(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); var resourceAttribute = resourceType.ClrType.GetCustomAttribute(); return resourceAttribute?.GenerateControllerEndpoints; diff --git a/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransaction.cs b/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransaction.cs index f59f86162d..d045bc0814 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransaction.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransaction.cs @@ -19,8 +19,8 @@ public sealed class EntityFrameworkCoreTransaction : IOperationsTransaction public EntityFrameworkCoreTransaction(IDbContextTransaction transaction, DbContext dbContext) { - ArgumentGuard.NotNull(transaction); - ArgumentGuard.NotNull(dbContext); + ArgumentNullException.ThrowIfNull(transaction); + ArgumentNullException.ThrowIfNull(dbContext); _transaction = transaction; _dbContext = dbContext; diff --git a/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransactionFactory.cs b/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransactionFactory.cs index 8ef44cb627..2fe6959b1f 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransactionFactory.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/EntityFrameworkCoreTransactionFactory.cs @@ -15,8 +15,8 @@ public sealed class EntityFrameworkCoreTransactionFactory : IOperationsTransacti public EntityFrameworkCoreTransactionFactory(IDbContextResolver dbContextResolver, IJsonApiOptions options) { - ArgumentGuard.NotNull(dbContextResolver); - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(dbContextResolver); + ArgumentNullException.ThrowIfNull(options); _dbContextResolver = dbContextResolver; _options = options; diff --git a/src/JsonApiDotNetCore/AtomicOperations/LocalIdTracker.cs b/src/JsonApiDotNetCore/AtomicOperations/LocalIdTracker.cs index 5d22198a72..bb058475e3 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/LocalIdTracker.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/LocalIdTracker.cs @@ -17,8 +17,8 @@ public void Reset() /// public void Declare(string localId, ResourceType resourceType) { - ArgumentGuard.NotNullNorEmpty(localId); - ArgumentGuard.NotNull(resourceType); + ArgumentException.ThrowIfNullOrEmpty(localId); + ArgumentNullException.ThrowIfNull(resourceType); AssertIsNotDeclared(localId); @@ -36,9 +36,9 @@ private void AssertIsNotDeclared(string localId) /// public void Assign(string localId, ResourceType resourceType, string stringId) { - ArgumentGuard.NotNullNorEmpty(localId); - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNullNorEmpty(stringId); + ArgumentException.ThrowIfNullOrEmpty(localId); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentException.ThrowIfNullOrEmpty(stringId); AssertIsDeclared(localId); @@ -57,8 +57,8 @@ public void Assign(string localId, ResourceType resourceType, string stringId) /// public string GetValue(string localId, ResourceType resourceType) { - ArgumentGuard.NotNullNorEmpty(localId); - ArgumentGuard.NotNull(resourceType); + ArgumentException.ThrowIfNullOrEmpty(localId); + ArgumentNullException.ThrowIfNull(resourceType); AssertIsDeclared(localId); diff --git a/src/JsonApiDotNetCore/AtomicOperations/LocalIdValidator.cs b/src/JsonApiDotNetCore/AtomicOperations/LocalIdValidator.cs index fb75fe3c7f..92d9bd8319 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/LocalIdValidator.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/LocalIdValidator.cs @@ -18,8 +18,8 @@ public sealed class LocalIdValidator public LocalIdValidator(ILocalIdTracker localIdTracker, IResourceGraph resourceGraph) { - ArgumentGuard.NotNull(localIdTracker); - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(localIdTracker); + ArgumentNullException.ThrowIfNull(resourceGraph); _localIdTracker = localIdTracker; _resourceGraph = resourceGraph; @@ -27,7 +27,7 @@ public LocalIdValidator(ILocalIdTracker localIdTracker, IResourceGraph resourceG public void Validate(IEnumerable operations) { - ArgumentGuard.NotNull(operations); + ArgumentNullException.ThrowIfNull(operations); _localIdTracker.Reset(); diff --git a/src/JsonApiDotNetCore/AtomicOperations/OperationProcessorAccessor.cs b/src/JsonApiDotNetCore/AtomicOperations/OperationProcessorAccessor.cs index 927bbf92d3..a6dc2051ec 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/OperationProcessorAccessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/OperationProcessorAccessor.cs @@ -15,7 +15,7 @@ public class OperationProcessorAccessor : IOperationProcessorAccessor public OperationProcessorAccessor(IServiceProvider serviceProvider) { - ArgumentGuard.NotNull(serviceProvider); + ArgumentNullException.ThrowIfNull(serviceProvider); _serviceProvider = serviceProvider; } @@ -23,7 +23,7 @@ public OperationProcessorAccessor(IServiceProvider serviceProvider) /// public Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); IOperationProcessor processor = ResolveProcessor(operation); return processor.ProcessAsync(operation, cancellationToken); @@ -31,7 +31,7 @@ public OperationProcessorAccessor(IServiceProvider serviceProvider) protected virtual IOperationProcessor ResolveProcessor(OperationContainer operation) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); Type processorInterface = GetProcessorInterface(operation.Request.WriteOperation!.Value); ResourceType resourceType = operation.Request.PrimaryResourceType!; diff --git a/src/JsonApiDotNetCore/AtomicOperations/OperationsProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/OperationsProcessor.cs index ff7a48dc32..f3d0b22256 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/OperationsProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/OperationsProcessor.cs @@ -25,13 +25,13 @@ public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccesso ILocalIdTracker localIdTracker, IResourceGraph resourceGraph, IJsonApiRequest request, ITargetedFields targetedFields, ISparseFieldSetCache sparseFieldSetCache) { - ArgumentGuard.NotNull(operationProcessorAccessor); - ArgumentGuard.NotNull(operationsTransactionFactory); - ArgumentGuard.NotNull(localIdTracker); - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(targetedFields); - ArgumentGuard.NotNull(sparseFieldSetCache); + ArgumentNullException.ThrowIfNull(operationProcessorAccessor); + ArgumentNullException.ThrowIfNull(operationsTransactionFactory); + ArgumentNullException.ThrowIfNull(localIdTracker); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(targetedFields); + ArgumentNullException.ThrowIfNull(sparseFieldSetCache); _operationProcessorAccessor = operationProcessorAccessor; _operationsTransactionFactory = operationsTransactionFactory; @@ -46,7 +46,7 @@ public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccesso /// public virtual async Task> ProcessAsync(IList operations, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operations); + ArgumentNullException.ThrowIfNull(operations); _localIdValidator.Validate(operations); _localIdTracker.Reset(); @@ -101,7 +101,7 @@ public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccesso protected virtual async Task ProcessOperationAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); cancellationToken.ThrowIfCancellationRequested(); @@ -115,7 +115,7 @@ public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccesso protected void TrackLocalIdsForOperation(OperationContainer operation) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); if (operation.Request.WriteOperation == WriteOperationKind.CreateResource) { diff --git a/src/JsonApiDotNetCore/AtomicOperations/Processors/AddToRelationshipProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/Processors/AddToRelationshipProcessor.cs index fa835910ef..e84756120a 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/Processors/AddToRelationshipProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/Processors/AddToRelationshipProcessor.cs @@ -13,7 +13,7 @@ public class AddToRelationshipProcessor : IAddToRelationshipProc public AddToRelationshipProcessor(IAddToRelationshipService service) { - ArgumentGuard.NotNull(service); + ArgumentNullException.ThrowIfNull(service); _service = service; } @@ -21,7 +21,7 @@ public AddToRelationshipProcessor(IAddToRelationshipService serv /// public virtual async Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); var leftId = (TId)operation.Resource.GetTypedId(); ISet rightResourceIds = operation.GetSecondaryResources(); diff --git a/src/JsonApiDotNetCore/AtomicOperations/Processors/CreateProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/Processors/CreateProcessor.cs index e4ccd7b69d..c7bf3c9b77 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/Processors/CreateProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/Processors/CreateProcessor.cs @@ -14,8 +14,8 @@ public class CreateProcessor : ICreateProcessor public CreateProcessor(ICreateService service, ILocalIdTracker localIdTracker) { - ArgumentGuard.NotNull(service); - ArgumentGuard.NotNull(localIdTracker); + ArgumentNullException.ThrowIfNull(service); + ArgumentNullException.ThrowIfNull(localIdTracker); _service = service; _localIdTracker = localIdTracker; @@ -24,7 +24,7 @@ public CreateProcessor(ICreateService service, ILocalIdTracker l /// public virtual async Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); TResource? newResource = await _service.CreateAsync((TResource)operation.Resource, cancellationToken); diff --git a/src/JsonApiDotNetCore/AtomicOperations/Processors/DeleteProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/Processors/DeleteProcessor.cs index d758e065bc..5709188a8c 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/Processors/DeleteProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/Processors/DeleteProcessor.cs @@ -13,7 +13,7 @@ public class DeleteProcessor : IDeleteProcessor public DeleteProcessor(IDeleteService service) { - ArgumentGuard.NotNull(service); + ArgumentNullException.ThrowIfNull(service); _service = service; } @@ -21,7 +21,7 @@ public DeleteProcessor(IDeleteService service) /// public virtual async Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); var id = (TId)operation.Resource.GetTypedId(); await _service.DeleteAsync(id!, cancellationToken); diff --git a/src/JsonApiDotNetCore/AtomicOperations/Processors/RemoveFromRelationshipProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/Processors/RemoveFromRelationshipProcessor.cs index 6222a01fd8..81c4eb93ee 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/Processors/RemoveFromRelationshipProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/Processors/RemoveFromRelationshipProcessor.cs @@ -13,7 +13,7 @@ public class RemoveFromRelationshipProcessor : IRemoveFromRelati public RemoveFromRelationshipProcessor(IRemoveFromRelationshipService service) { - ArgumentGuard.NotNull(service); + ArgumentNullException.ThrowIfNull(service); _service = service; } @@ -21,7 +21,7 @@ public RemoveFromRelationshipProcessor(IRemoveFromRelationshipService public virtual async Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); var leftId = (TId)operation.Resource.GetTypedId(); ISet rightResourceIds = operation.GetSecondaryResources(); diff --git a/src/JsonApiDotNetCore/AtomicOperations/Processors/SetRelationshipProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/Processors/SetRelationshipProcessor.cs index abc40c4812..913068a26c 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/Processors/SetRelationshipProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/Processors/SetRelationshipProcessor.cs @@ -14,7 +14,7 @@ public class SetRelationshipProcessor : ISetRelationshipProcesso public SetRelationshipProcessor(ISetRelationshipService service) { - ArgumentGuard.NotNull(service); + ArgumentNullException.ThrowIfNull(service); _service = service; } @@ -22,7 +22,7 @@ public SetRelationshipProcessor(ISetRelationshipService service) /// public virtual async Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); var leftId = (TId)operation.Resource.GetTypedId(); object? rightValue = GetRelationshipRightValue(operation); diff --git a/src/JsonApiDotNetCore/AtomicOperations/Processors/UpdateProcessor.cs b/src/JsonApiDotNetCore/AtomicOperations/Processors/UpdateProcessor.cs index 32fe2a1eb5..cf66c70462 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/Processors/UpdateProcessor.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/Processors/UpdateProcessor.cs @@ -13,7 +13,7 @@ public class UpdateProcessor : IUpdateProcessor public UpdateProcessor(IUpdateService service) { - ArgumentGuard.NotNull(service); + ArgumentNullException.ThrowIfNull(service); _service = service; } @@ -21,7 +21,7 @@ public UpdateProcessor(IUpdateService service) /// public virtual async Task ProcessAsync(OperationContainer operation, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(operation); + ArgumentNullException.ThrowIfNull(operation); var resource = (TResource)operation.Resource; TResource? updated = await _service.UpdateAsync(resource.Id!, resource, cancellationToken); diff --git a/src/JsonApiDotNetCore/AtomicOperations/RevertRequestStateOnDispose.cs b/src/JsonApiDotNetCore/AtomicOperations/RevertRequestStateOnDispose.cs index 824e69de74..82b0641c34 100644 --- a/src/JsonApiDotNetCore/AtomicOperations/RevertRequestStateOnDispose.cs +++ b/src/JsonApiDotNetCore/AtomicOperations/RevertRequestStateOnDispose.cs @@ -16,7 +16,7 @@ internal sealed class RevertRequestStateOnDispose : IDisposable public RevertRequestStateOnDispose(IJsonApiRequest request, ITargetedFields? targetedFields) { - ArgumentGuard.NotNull(request); + ArgumentNullException.ThrowIfNull(request); _sourceRequest = request; _backupRequest.CopyFrom(request); diff --git a/src/JsonApiDotNetCore/CollectionExtensions.cs b/src/JsonApiDotNetCore/CollectionExtensions.cs index 05ed03f328..ca46953bfc 100644 --- a/src/JsonApiDotNetCore/CollectionExtensions.cs +++ b/src/JsonApiDotNetCore/CollectionExtensions.cs @@ -18,7 +18,7 @@ public static bool IsNullOrEmpty([NotNullWhen(false)] this IEnumerable? so public static int FindIndex(this IReadOnlyList source, T item) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); for (int index = 0; index < source.Count; index++) { @@ -33,8 +33,8 @@ public static int FindIndex(this IReadOnlyList source, T item) public static int FindIndex(this IReadOnlyList source, Predicate match) { - ArgumentGuard.NotNull(source); - ArgumentGuard.NotNull(match); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(match); for (int index = 0; index < source.Count; index++) { diff --git a/src/JsonApiDotNetCore/Configuration/ApplicationBuilderExtensions.cs b/src/JsonApiDotNetCore/Configuration/ApplicationBuilderExtensions.cs index 8ed4e42a42..349cb20dd9 100644 --- a/src/JsonApiDotNetCore/Configuration/ApplicationBuilderExtensions.cs +++ b/src/JsonApiDotNetCore/Configuration/ApplicationBuilderExtensions.cs @@ -22,7 +22,7 @@ public static class ApplicationBuilderExtensions /// public static void UseJsonApi(this IApplicationBuilder builder) { - ArgumentGuard.NotNull(builder); + ArgumentNullException.ThrowIfNull(builder); using (IServiceScope scope = builder.ApplicationServices.CreateScope()) { diff --git a/src/JsonApiDotNetCore/Configuration/DefaultJsonApiApplicationBuilderEvents.cs b/src/JsonApiDotNetCore/Configuration/DefaultJsonApiApplicationBuilderEvents.cs index dbab4e076b..c1bea78418 100644 --- a/src/JsonApiDotNetCore/Configuration/DefaultJsonApiApplicationBuilderEvents.cs +++ b/src/JsonApiDotNetCore/Configuration/DefaultJsonApiApplicationBuilderEvents.cs @@ -8,7 +8,7 @@ internal sealed class DefaultJsonApiApplicationBuilderEvents : IJsonApiApplicati public DefaultJsonApiApplicationBuilderEvents(IJsonApiOptions options) { - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(options); _options = options; } diff --git a/src/JsonApiDotNetCore/Configuration/InjectablesAssemblyScanner.cs b/src/JsonApiDotNetCore/Configuration/InjectablesAssemblyScanner.cs index 9985533776..3ac71053b0 100644 --- a/src/JsonApiDotNetCore/Configuration/InjectablesAssemblyScanner.cs +++ b/src/JsonApiDotNetCore/Configuration/InjectablesAssemblyScanner.cs @@ -46,8 +46,8 @@ internal sealed class InjectablesAssemblyScanner public InjectablesAssemblyScanner(ResourceDescriptorAssemblyCache assemblyCache, IServiceCollection services) { - ArgumentGuard.NotNull(assemblyCache); - ArgumentGuard.NotNull(services); + ArgumentNullException.ThrowIfNull(assemblyCache); + ArgumentNullException.ThrowIfNull(services); _assemblyCache = assemblyCache; _services = services; diff --git a/src/JsonApiDotNetCore/Configuration/InverseNavigationResolver.cs b/src/JsonApiDotNetCore/Configuration/InverseNavigationResolver.cs index 270444928e..4527afdcbe 100644 --- a/src/JsonApiDotNetCore/Configuration/InverseNavigationResolver.cs +++ b/src/JsonApiDotNetCore/Configuration/InverseNavigationResolver.cs @@ -15,8 +15,8 @@ public sealed class InverseNavigationResolver : IInverseNavigationResolver public InverseNavigationResolver(IResourceGraph resourceGraph, IEnumerable dbContextResolvers) { - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(dbContextResolvers); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(dbContextResolvers); _resourceGraph = resourceGraph; _dbContextResolvers = dbContextResolvers as IDbContextResolver[] ?? dbContextResolvers.ToArray(); diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs b/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs index 8dc8f47b77..65646b7697 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs @@ -36,8 +36,8 @@ internal sealed class JsonApiApplicationBuilder : IJsonApiApplicationBuilder public JsonApiApplicationBuilder(IServiceCollection services, IMvcCoreBuilder mvcBuilder) { - ArgumentGuard.NotNull(services); - ArgumentGuard.NotNull(mvcBuilder); + ArgumentNullException.ThrowIfNull(services); + ArgumentNullException.ThrowIfNull(mvcBuilder); _services = services; _mvcBuilder = mvcBuilder; @@ -68,7 +68,7 @@ public void ConfigureAutoDiscovery(Action? configureAuto /// public void ConfigureResourceGraph(ICollection dbContextTypes, Action? configureResourceGraph) { - ArgumentGuard.NotNull(dbContextTypes); + ArgumentNullException.ThrowIfNull(dbContextTypes); _services.TryAddSingleton(serviceProvider => { @@ -135,7 +135,7 @@ public void DiscoverInjectables() /// public void ConfigureServiceContainer(ICollection dbContextTypes) { - ArgumentGuard.NotNull(dbContextTypes); + ArgumentNullException.ThrowIfNull(dbContextTypes); if (dbContextTypes.Count > 0) { diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiModelMetadataProvider.cs b/src/JsonApiDotNetCore/Configuration/JsonApiModelMetadataProvider.cs index 2aaa218be7..5e1941a165 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiModelMetadataProvider.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiModelMetadataProvider.cs @@ -31,7 +31,7 @@ public JsonApiModelMetadataProvider(ICompositeMetadataDetailsProvider detailsPro /// protected override ModelMetadata CreateModelMetadata(DefaultMetadataDetails entry) { - ArgumentGuard.NotNull(entry); + ArgumentNullException.ThrowIfNull(entry); var metadata = (DefaultModelMetadata)base.CreateModelMetadata(entry); metadata.ValidationMetadata.PropertyValidationFilter = _jsonApiValidationFilter; diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs index 084070b27c..182c51431b 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs @@ -144,7 +144,7 @@ public JsonApiOptions() /// public void IncludeExtensions(params JsonApiMediaTypeExtension[] extensionsToAdd) { - ArgumentGuard.NotNull(extensionsToAdd); + ArgumentNullException.ThrowIfNull(extensionsToAdd); if (!Extensions.IsSupersetOf(extensionsToAdd)) { diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiValidationFilter.cs b/src/JsonApiDotNetCore/Configuration/JsonApiValidationFilter.cs index 3fd29a9c65..30b850e8b8 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiValidationFilter.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiValidationFilter.cs @@ -16,7 +16,7 @@ internal sealed class JsonApiValidationFilter : IPropertyValidationFilter public JsonApiValidationFilter(IHttpContextAccessor httpContextAccessor) { - ArgumentGuard.NotNull(httpContextAccessor); + ArgumentNullException.ThrowIfNull(httpContextAccessor); _httpContextAccessor = httpContextAccessor; } diff --git a/src/JsonApiDotNetCore/Configuration/ResourceDescriptor.cs b/src/JsonApiDotNetCore/Configuration/ResourceDescriptor.cs index 885f67567c..9c0ce2cf30 100644 --- a/src/JsonApiDotNetCore/Configuration/ResourceDescriptor.cs +++ b/src/JsonApiDotNetCore/Configuration/ResourceDescriptor.cs @@ -7,8 +7,8 @@ internal sealed class ResourceDescriptor public ResourceDescriptor(Type resourceClrType, Type idClrType) { - ArgumentGuard.NotNull(resourceClrType); - ArgumentGuard.NotNull(idClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); + ArgumentNullException.ThrowIfNull(idClrType); ResourceClrType = resourceClrType; IdClrType = idClrType; diff --git a/src/JsonApiDotNetCore/Configuration/ResourceGraph.cs b/src/JsonApiDotNetCore/Configuration/ResourceGraph.cs index b0eddedc91..a4ffd082d3 100644 --- a/src/JsonApiDotNetCore/Configuration/ResourceGraph.cs +++ b/src/JsonApiDotNetCore/Configuration/ResourceGraph.cs @@ -19,7 +19,7 @@ public sealed class ResourceGraph : IResourceGraph public ResourceGraph(IReadOnlySet resourceTypeSet) { - ArgumentGuard.NotNull(resourceTypeSet); + ArgumentNullException.ThrowIfNull(resourceTypeSet); _resourceTypeSet = resourceTypeSet; @@ -52,7 +52,7 @@ public ResourceType GetResourceType(string publicName) /// public ResourceType? FindResourceType(string publicName) { - ArgumentGuard.NotNull(publicName); + ArgumentNullException.ThrowIfNull(publicName); return _resourceTypesByPublicName.GetValueOrDefault(publicName); } @@ -73,7 +73,7 @@ public ResourceType GetResourceType(Type resourceClrType) /// public ResourceType? FindResourceType(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); Type typeToFind = IsLazyLoadingProxyForResourceType(resourceClrType) ? resourceClrType.BaseType! : resourceClrType; return _resourceTypesByClrType.GetValueOrDefault(typeToFind); @@ -95,7 +95,7 @@ public ResourceType GetResourceType() public IReadOnlyCollection GetFields(Expression> selector) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(selector); + ArgumentNullException.ThrowIfNull(selector); return FilterFields(selector); } @@ -104,7 +104,7 @@ public IReadOnlyCollection GetFields(Expressi public IReadOnlyCollection GetAttributes(Expression> selector) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(selector); + ArgumentNullException.ThrowIfNull(selector); return FilterFields(selector); } @@ -113,7 +113,7 @@ public IReadOnlyCollection GetAttributes(Expression GetRelationships(Expression> selector) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(selector); + ArgumentNullException.ThrowIfNull(selector); return FilterFields(selector); } diff --git a/src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs b/src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs index 159ce5be69..5233db578f 100644 --- a/src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs @@ -23,8 +23,8 @@ public partial class ResourceGraphBuilder public ResourceGraphBuilder(IJsonApiOptions options, ILoggerFactory loggerFactory) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(loggerFactory); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(loggerFactory); _options = options; _logger = loggerFactory.CreateLogger(); @@ -149,7 +149,7 @@ private static void ValidateRelationshipsInDerivedType(ResourceType resourceType public ResourceGraphBuilder Add(DbContext dbContext) { - ArgumentGuard.NotNull(dbContext); + ArgumentNullException.ThrowIfNull(dbContext); foreach (IEntityType entityType in dbContext.Model.GetEntityTypes()) { @@ -205,7 +205,7 @@ public ResourceGraphBuilder Add(string? publicName = null) public ResourceGraphBuilder Add(Type resourceClrType, Type? idClrType = null, string? publicName = null) #pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); if (_resourceTypesByClrType.ContainsKey(resourceClrType)) { diff --git a/src/JsonApiDotNetCore/Configuration/ResourceNameFormatter.cs b/src/JsonApiDotNetCore/Configuration/ResourceNameFormatter.cs index 6a5a09dcaf..0531c25ca9 100644 --- a/src/JsonApiDotNetCore/Configuration/ResourceNameFormatter.cs +++ b/src/JsonApiDotNetCore/Configuration/ResourceNameFormatter.cs @@ -14,7 +14,7 @@ internal sealed class ResourceNameFormatter(JsonNamingPolicy? namingPolicy) /// public string FormatResourceName(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); var resourceAttribute = resourceClrType.GetCustomAttribute(true); diff --git a/src/JsonApiDotNetCore/Configuration/ResourcesAssemblyScanner.cs b/src/JsonApiDotNetCore/Configuration/ResourcesAssemblyScanner.cs index cdfdc4446c..f2dcf827d3 100644 --- a/src/JsonApiDotNetCore/Configuration/ResourcesAssemblyScanner.cs +++ b/src/JsonApiDotNetCore/Configuration/ResourcesAssemblyScanner.cs @@ -12,8 +12,8 @@ internal sealed class ResourcesAssemblyScanner public ResourcesAssemblyScanner(ResourceDescriptorAssemblyCache assemblyCache, ResourceGraphBuilder resourceGraphBuilder) { - ArgumentGuard.NotNull(assemblyCache); - ArgumentGuard.NotNull(resourceGraphBuilder); + ArgumentNullException.ThrowIfNull(assemblyCache); + ArgumentNullException.ThrowIfNull(resourceGraphBuilder); _assemblyCache = assemblyCache; _resourceGraphBuilder = resourceGraphBuilder; diff --git a/src/JsonApiDotNetCore/Configuration/ServiceCollectionExtensions.cs b/src/JsonApiDotNetCore/Configuration/ServiceCollectionExtensions.cs index 5ad4474d95..65bf465ce3 100644 --- a/src/JsonApiDotNetCore/Configuration/ServiceCollectionExtensions.cs +++ b/src/JsonApiDotNetCore/Configuration/ServiceCollectionExtensions.cs @@ -22,7 +22,7 @@ public static IServiceCollection AddJsonApi(this IServiceCollection services, Ac ICollection? dbContextTypes = null) #pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks { - ArgumentGuard.NotNull(services); + ArgumentNullException.ThrowIfNull(services); SetupApplicationBuilder(services, options, discovery, resources, mvcBuilder, dbContextTypes ?? Array.Empty()); @@ -59,7 +59,7 @@ private static void SetupApplicationBuilder(IServiceCollection services, Action< /// public static IServiceCollection AddResourceService(this IServiceCollection services) { - ArgumentGuard.NotNull(services); + ArgumentNullException.ThrowIfNull(services); RegisterTypeForUnboundInterfaces(services, typeof(TService), InjectablesAssemblyScanner.ServiceUnboundInterfaces); @@ -72,7 +72,7 @@ public static IServiceCollection AddResourceService(this IServiceColle /// public static IServiceCollection AddResourceRepository(this IServiceCollection services) { - ArgumentGuard.NotNull(services); + ArgumentNullException.ThrowIfNull(services); RegisterTypeForUnboundInterfaces(services, typeof(TRepository), InjectablesAssemblyScanner.RepositoryUnboundInterfaces); @@ -85,7 +85,7 @@ public static IServiceCollection AddResourceRepository(this IServic /// public static IServiceCollection AddResourceDefinition(this IServiceCollection services) { - ArgumentGuard.NotNull(services); + ArgumentNullException.ThrowIfNull(services); RegisterTypeForUnboundInterfaces(services, typeof(TResourceDefinition), InjectablesAssemblyScanner.ResourceDefinitionUnboundInterfaces); diff --git a/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs b/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs index 615ef244fc..d28b8381c6 100644 --- a/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs +++ b/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs @@ -13,7 +13,7 @@ public sealed class ServiceDiscoveryFacade internal ServiceDiscoveryFacade(ResourceDescriptorAssemblyCache assemblyCache) { - ArgumentGuard.NotNull(assemblyCache); + ArgumentNullException.ThrowIfNull(assemblyCache); _assemblyCache = assemblyCache; } @@ -31,7 +31,7 @@ public ServiceDiscoveryFacade AddCurrentAssembly() /// public ServiceDiscoveryFacade AddAssembly(Assembly assembly) { - ArgumentGuard.NotNull(assembly); + ArgumentNullException.ThrowIfNull(assembly); _assemblyCache.RegisterAssembly(assembly); return this; diff --git a/src/JsonApiDotNetCore/Configuration/TypeLocator.cs b/src/JsonApiDotNetCore/Configuration/TypeLocator.cs index bce31946f1..6b8c545744 100644 --- a/src/JsonApiDotNetCore/Configuration/TypeLocator.cs +++ b/src/JsonApiDotNetCore/Configuration/TypeLocator.cs @@ -66,9 +66,9 @@ internal sealed class TypeLocator public (Type implementationType, Type serviceInterface)? GetContainerRegistrationFromAssembly(Assembly assembly, Type unboundInterface, params Type[] interfaceTypeArguments) { - ArgumentGuard.NotNull(assembly); - ArgumentGuard.NotNull(unboundInterface); - ArgumentGuard.NotNull(interfaceTypeArguments); + ArgumentNullException.ThrowIfNull(assembly); + ArgumentNullException.ThrowIfNull(unboundInterface); + ArgumentNullException.ThrowIfNull(interfaceTypeArguments); if (!unboundInterface.IsInterface || !unboundInterface.IsGenericType || unboundInterface != unboundInterface.GetGenericTypeDefinition()) { @@ -126,8 +126,8 @@ private static (Type implementationType, Type serviceInterface)? GetContainerReg /// public IEnumerable GetDerivedTypes(Assembly assembly, Type baseType) { - ArgumentGuard.NotNull(assembly); - ArgumentGuard.NotNull(baseType); + ArgumentNullException.ThrowIfNull(assembly); + ArgumentNullException.ThrowIfNull(baseType); foreach (Type type in assembly.GetTypes()) { diff --git a/src/JsonApiDotNetCore/Controllers/Annotations/DisableQueryStringAttribute.cs b/src/JsonApiDotNetCore/Controllers/Annotations/DisableQueryStringAttribute.cs index b659fdc370..d90d67118e 100644 --- a/src/JsonApiDotNetCore/Controllers/Annotations/DisableQueryStringAttribute.cs +++ b/src/JsonApiDotNetCore/Controllers/Annotations/DisableQueryStringAttribute.cs @@ -46,7 +46,7 @@ public DisableQueryStringAttribute(JsonApiQueryStringParameters parameters) /// public DisableQueryStringAttribute(string parameterNames) { - ArgumentGuard.NotNullNorEmpty(parameterNames); + ArgumentException.ThrowIfNullOrEmpty(parameterNames); ParameterNames = parameterNames.Split(",").ToHashSet().AsReadOnly(); } diff --git a/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs b/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs index d293a98701..acd6528500 100644 --- a/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs +++ b/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs @@ -66,9 +66,9 @@ protected BaseJsonApiController(IJsonApiOptions options, IResourceGraph resource IUpdateService? update = null, ISetRelationshipService? setRelationship = null, IDeleteService? delete = null, IRemoveFromRelationshipService? removeFromRelationship = null) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(loggerFactory); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(loggerFactory); _options = options; _resourceGraph = resourceGraph; @@ -143,7 +143,7 @@ public virtual async Task GetSecondaryAsync([DisallowNull] TId id relationshipName }); - ArgumentGuard.NotNull(relationshipName); + ArgumentNullException.ThrowIfNull(relationshipName); if (_getSecondary == null) { @@ -173,7 +173,7 @@ public virtual async Task GetRelationshipAsync([DisallowNull] TId relationshipName }); - ArgumentGuard.NotNull(relationshipName); + ArgumentNullException.ThrowIfNull(relationshipName); if (_getRelationship == null) { @@ -197,7 +197,7 @@ public virtual async Task PostAsync([FromBody] TResource resource resource }); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); if (_create == null) { @@ -259,8 +259,8 @@ public virtual async Task PostRelationshipAsync([DisallowNull] TI rightResourceIds }); - ArgumentGuard.NotNull(relationshipName); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(relationshipName); + ArgumentNullException.ThrowIfNull(rightResourceIds); if (_addToRelationship == null) { @@ -286,7 +286,7 @@ public virtual async Task PatchAsync([DisallowNull] TId id, [From resource }); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); if (_update == null) { @@ -334,7 +334,7 @@ public virtual async Task PatchRelationshipAsync([DisallowNull] T rightValue }); - ArgumentGuard.NotNull(relationshipName); + ArgumentNullException.ThrowIfNull(relationshipName); if (_setRelationship == null) { @@ -395,8 +395,8 @@ public virtual async Task DeleteRelationshipAsync([DisallowNull] rightResourceIds }); - ArgumentGuard.NotNull(relationshipName); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(relationshipName); + ArgumentNullException.ThrowIfNull(rightResourceIds); if (_removeFromRelationship == null) { diff --git a/src/JsonApiDotNetCore/Controllers/BaseJsonApiOperationsController.cs b/src/JsonApiDotNetCore/Controllers/BaseJsonApiOperationsController.cs index 3c8ebac01a..6c6703c132 100644 --- a/src/JsonApiDotNetCore/Controllers/BaseJsonApiOperationsController.cs +++ b/src/JsonApiDotNetCore/Controllers/BaseJsonApiOperationsController.cs @@ -30,13 +30,13 @@ public abstract class BaseJsonApiOperationsController : CoreJsonApiController protected BaseJsonApiOperationsController(IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request, ITargetedFields targetedFields, IAtomicOperationFilter operationFilter) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(loggerFactory); - ArgumentGuard.NotNull(processor); - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(targetedFields); - ArgumentGuard.NotNull(operationFilter); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(loggerFactory); + ArgumentNullException.ThrowIfNull(processor); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(targetedFields); + ArgumentNullException.ThrowIfNull(operationFilter); _options = options; _resourceGraph = resourceGraph; @@ -114,7 +114,7 @@ public virtual async Task PostOperationsAsync([FromBody] IList PostOperationsAsync([FromBody] IList operations) { - ArgumentGuard.NotNull(operations); + ArgumentNullException.ThrowIfNull(operations); List errors = []; @@ -193,7 +193,7 @@ private static string GetOperationCodeText(WriteOperationKind writeOperation) protected virtual void ValidateModelState(IList operations) { - ArgumentGuard.NotNull(operations); + ArgumentNullException.ThrowIfNull(operations); // We must validate the resource inside each operation manually, because they are typed as IIdentifiable. // Instead of validating IIdentifiable we need to validate the resource runtime-type. diff --git a/src/JsonApiDotNetCore/Controllers/CoreJsonApiController.cs b/src/JsonApiDotNetCore/Controllers/CoreJsonApiController.cs index 332a9bf255..f81ec9d071 100644 --- a/src/JsonApiDotNetCore/Controllers/CoreJsonApiController.cs +++ b/src/JsonApiDotNetCore/Controllers/CoreJsonApiController.cs @@ -11,7 +11,7 @@ public abstract class CoreJsonApiController : ControllerBase { protected IActionResult Error(ErrorObject error) { - ArgumentGuard.NotNull(error); + ArgumentNullException.ThrowIfNull(error); return new ObjectResult(error) { diff --git a/src/JsonApiDotNetCore/Diagnostics/AspNetCodeTimerSession.cs b/src/JsonApiDotNetCore/Diagnostics/AspNetCodeTimerSession.cs index a42d734580..9b58dc43e7 100644 --- a/src/JsonApiDotNetCore/Diagnostics/AspNetCodeTimerSession.cs +++ b/src/JsonApiDotNetCore/Diagnostics/AspNetCodeTimerSession.cs @@ -37,14 +37,14 @@ public ICodeTimer CodeTimer public AspNetCodeTimerSession(IHttpContextAccessor httpContextAccessor) { - ArgumentGuard.NotNull(httpContextAccessor); + ArgumentNullException.ThrowIfNull(httpContextAccessor); _httpContextAccessor = httpContextAccessor; } public AspNetCodeTimerSession(HttpContext httpContext) { - ArgumentGuard.NotNull(httpContext); + ArgumentNullException.ThrowIfNull(httpContext); _httpContext = httpContext; } diff --git a/src/JsonApiDotNetCore/Diagnostics/CodeTimingSessionManager.cs b/src/JsonApiDotNetCore/Diagnostics/CodeTimingSessionManager.cs index 47f4007db0..052784d0d6 100644 --- a/src/JsonApiDotNetCore/Diagnostics/CodeTimingSessionManager.cs +++ b/src/JsonApiDotNetCore/Diagnostics/CodeTimingSessionManager.cs @@ -62,7 +62,7 @@ private static void AssertHasActiveSession() public static void Capture(ICodeTimerSession session) { - ArgumentGuard.NotNull(session); + ArgumentNullException.ThrowIfNull(session); AssertNoActiveSession(); diff --git a/src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs b/src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs index ccf23e1eb5..fc85156e57 100644 --- a/src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs +++ b/src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs @@ -23,9 +23,9 @@ public sealed class InvalidModelStateException( private static List FromModelStateDictionary(IReadOnlyDictionary modelState, Type modelType, IResourceGraph resourceGraph, bool includeExceptionStackTraceInErrors, Func? getCollectionElementTypeCallback) { - ArgumentGuard.NotNull(modelState); - ArgumentGuard.NotNull(modelType); - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(modelState); + ArgumentNullException.ThrowIfNull(modelType); + ArgumentNullException.ThrowIfNull(resourceGraph); List errorObjects = []; @@ -231,8 +231,8 @@ private abstract class ModelStateKeySegment protected ModelStateKeySegment(Type modelType, bool isInComplexType, string nextKey, string? sourcePointer, ModelStateKeySegment? parent, Func? getCollectionElementTypeCallback) { - ArgumentGuard.NotNull(modelType); - ArgumentGuard.NotNull(nextKey); + ArgumentNullException.ThrowIfNull(modelType); + ArgumentNullException.ThrowIfNull(nextKey); ModelType = modelType; IsInComplexType = isInComplexType; @@ -244,15 +244,15 @@ protected ModelStateKeySegment(Type modelType, bool isInComplexType, string next public ModelStateKeySegment? GetNextSegment(Type modelType, bool isInComplexType, string? sourcePointer) { - ArgumentGuard.NotNull(modelType); + ArgumentNullException.ThrowIfNull(modelType); return _nextKey.Length == 0 ? null : CreateSegment(modelType, _nextKey, isInComplexType, this, sourcePointer, GetCollectionElementTypeCallback); } public static ModelStateKeySegment Create(Type modelType, string key, Func? getCollectionElementTypeCallback) { - ArgumentGuard.NotNull(modelType); - ArgumentGuard.NotNull(key); + ArgumentNullException.ThrowIfNull(modelType); + ArgumentNullException.ThrowIfNull(key); return CreateSegment(modelType, key, false, null, null, getCollectionElementTypeCallback); } @@ -355,14 +355,14 @@ public PropertySegment(string propertyName, Type modelType, bool isInComplexType Func? getCollectionElementTypeCallback) : base(modelType, isInComplexType, nextKey, sourcePointer, parent, getCollectionElementTypeCallback) { - ArgumentGuard.NotNull(propertyName); + ArgumentNullException.ThrowIfNull(propertyName); PropertyName = propertyName; } public static string GetPublicNameForProperty(PropertyInfo property) { - ArgumentGuard.NotNull(property); + ArgumentNullException.ThrowIfNull(property); var jsonNameAttribute = property.GetCustomAttribute(true); return jsonNameAttribute?.Name ?? property.Name; diff --git a/src/JsonApiDotNetCore/Errors/JsonApiException.cs b/src/JsonApiDotNetCore/Errors/JsonApiException.cs index 1f15a127b4..b44b18d5a8 100644 --- a/src/JsonApiDotNetCore/Errors/JsonApiException.cs +++ b/src/JsonApiDotNetCore/Errors/JsonApiException.cs @@ -25,7 +25,7 @@ public class JsonApiException : Exception public JsonApiException(ErrorObject error, Exception? innerException = null) : base(null, innerException) { - ArgumentGuard.NotNull(error); + ArgumentNullException.ThrowIfNull(error); Errors = [error]; } diff --git a/src/JsonApiDotNetCore/Errors/MissingResourceInRelationship.cs b/src/JsonApiDotNetCore/Errors/MissingResourceInRelationship.cs index c2afd80cbf..de38f61fcd 100644 --- a/src/JsonApiDotNetCore/Errors/MissingResourceInRelationship.cs +++ b/src/JsonApiDotNetCore/Errors/MissingResourceInRelationship.cs @@ -11,9 +11,9 @@ public sealed class MissingResourceInRelationship public MissingResourceInRelationship(string relationshipName, string resourceType, string resourceId) { - ArgumentGuard.NotNull(relationshipName); - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(resourceId); + ArgumentNullException.ThrowIfNull(relationshipName); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceId); RelationshipName = relationshipName; ResourceType = resourceType; diff --git a/src/JsonApiDotNetCore/Errors/UnsuccessfulActionResultException.cs b/src/JsonApiDotNetCore/Errors/UnsuccessfulActionResultException.cs index 16f79db822..9e8083f7dc 100644 --- a/src/JsonApiDotNetCore/Errors/UnsuccessfulActionResultException.cs +++ b/src/JsonApiDotNetCore/Errors/UnsuccessfulActionResultException.cs @@ -27,7 +27,7 @@ public UnsuccessfulActionResultException(ProblemDetails problemDetails) private static IEnumerable ToErrorObjects(ProblemDetails problemDetails) { - ArgumentGuard.NotNull(problemDetails); + ArgumentNullException.ThrowIfNull(problemDetails); HttpStatusCode status = problemDetails.Status != null ? (HttpStatusCode)problemDetails.Status.Value : HttpStatusCode.InternalServerError; diff --git a/src/JsonApiDotNetCore/Middleware/AsyncConvertEmptyActionResultFilter.cs b/src/JsonApiDotNetCore/Middleware/AsyncConvertEmptyActionResultFilter.cs index a895c20ba4..440d3e69ea 100644 --- a/src/JsonApiDotNetCore/Middleware/AsyncConvertEmptyActionResultFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/AsyncConvertEmptyActionResultFilter.cs @@ -10,8 +10,8 @@ public sealed class AsyncConvertEmptyActionResultFilter : IAsyncConvertEmptyActi /// public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { - ArgumentGuard.NotNull(context); - ArgumentGuard.NotNull(next); + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(next); if (context.HttpContext.IsJsonApiRequest()) { diff --git a/src/JsonApiDotNetCore/Middleware/AsyncJsonApiExceptionFilter.cs b/src/JsonApiDotNetCore/Middleware/AsyncJsonApiExceptionFilter.cs index 45a0b96891..915747de8b 100644 --- a/src/JsonApiDotNetCore/Middleware/AsyncJsonApiExceptionFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/AsyncJsonApiExceptionFilter.cs @@ -13,7 +13,7 @@ public sealed class AsyncJsonApiExceptionFilter : IAsyncJsonApiExceptionFilter public AsyncJsonApiExceptionFilter(IExceptionHandler exceptionHandler) { - ArgumentGuard.NotNull(exceptionHandler); + ArgumentNullException.ThrowIfNull(exceptionHandler); _exceptionHandler = exceptionHandler; } @@ -21,7 +21,7 @@ public AsyncJsonApiExceptionFilter(IExceptionHandler exceptionHandler) /// public Task OnExceptionAsync(ExceptionContext context) { - ArgumentGuard.NotNull(context); + ArgumentNullException.ThrowIfNull(context); if (context.HttpContext.IsJsonApiRequest()) { diff --git a/src/JsonApiDotNetCore/Middleware/AsyncQueryStringActionFilter.cs b/src/JsonApiDotNetCore/Middleware/AsyncQueryStringActionFilter.cs index 6c394a531f..e832b4693a 100644 --- a/src/JsonApiDotNetCore/Middleware/AsyncQueryStringActionFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/AsyncQueryStringActionFilter.cs @@ -12,7 +12,7 @@ public sealed class AsyncQueryStringActionFilter : IAsyncQueryStringActionFilter public AsyncQueryStringActionFilter(IQueryStringReader queryStringReader) { - ArgumentGuard.NotNull(queryStringReader); + ArgumentNullException.ThrowIfNull(queryStringReader); _queryStringReader = queryStringReader; } @@ -20,8 +20,8 @@ public AsyncQueryStringActionFilter(IQueryStringReader queryStringReader) /// public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { - ArgumentGuard.NotNull(context); - ArgumentGuard.NotNull(next); + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(next); if (context.HttpContext.IsJsonApiRequest()) { diff --git a/src/JsonApiDotNetCore/Middleware/ExceptionHandler.cs b/src/JsonApiDotNetCore/Middleware/ExceptionHandler.cs index 0712f659ac..44e1b384ef 100644 --- a/src/JsonApiDotNetCore/Middleware/ExceptionHandler.cs +++ b/src/JsonApiDotNetCore/Middleware/ExceptionHandler.cs @@ -17,8 +17,8 @@ public partial class ExceptionHandler : IExceptionHandler public ExceptionHandler(ILoggerFactory loggerFactory, IJsonApiOptions options) { - ArgumentGuard.NotNull(loggerFactory); - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(loggerFactory); + ArgumentNullException.ThrowIfNull(options); _options = options; _logger = loggerFactory.CreateLogger(); @@ -26,7 +26,7 @@ public ExceptionHandler(ILoggerFactory loggerFactory, IJsonApiOptions options) public IReadOnlyList HandleException(Exception exception) { - ArgumentGuard.NotNull(exception); + ArgumentNullException.ThrowIfNull(exception); Exception demystified = exception.Demystify(); @@ -45,7 +45,7 @@ private void LogException(Exception exception) protected virtual LogLevel GetLogLevel(Exception exception) { - ArgumentGuard.NotNull(exception); + ArgumentNullException.ThrowIfNull(exception); if (exception is OperationCanceledException) { @@ -62,14 +62,14 @@ protected virtual LogLevel GetLogLevel(Exception exception) protected virtual string GetLogMessage(Exception exception) { - ArgumentGuard.NotNull(exception); + ArgumentNullException.ThrowIfNull(exception); return exception is JsonApiException jsonApiException ? jsonApiException.GetSummary() : exception.Message; } protected virtual IReadOnlyList CreateErrorResponse(Exception exception) { - ArgumentGuard.NotNull(exception); + ArgumentNullException.ThrowIfNull(exception); IReadOnlyList errors = exception switch { diff --git a/src/JsonApiDotNetCore/Middleware/HttpContextExtensions.cs b/src/JsonApiDotNetCore/Middleware/HttpContextExtensions.cs index a675aeeaff..85de6e92fb 100644 --- a/src/JsonApiDotNetCore/Middleware/HttpContextExtensions.cs +++ b/src/JsonApiDotNetCore/Middleware/HttpContextExtensions.cs @@ -13,7 +13,7 @@ public static class HttpContextExtensions /// public static bool IsJsonApiRequest(this HttpContext httpContext) { - ArgumentGuard.NotNull(httpContext); + ArgumentNullException.ThrowIfNull(httpContext); string? value = httpContext.Items[IsJsonApiRequestKey] as string; return value == bool.TrueString; @@ -21,7 +21,7 @@ public static bool IsJsonApiRequest(this HttpContext httpContext) internal static void RegisterJsonApiRequest(this HttpContext httpContext) { - ArgumentGuard.NotNull(httpContext); + ArgumentNullException.ThrowIfNull(httpContext); httpContext.Items[IsJsonApiRequestKey] = bool.TrueString; } diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiContentNegotiator.cs b/src/JsonApiDotNetCore/Middleware/JsonApiContentNegotiator.cs index 9cc366b282..a9806129f8 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiContentNegotiator.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiContentNegotiator.cs @@ -30,8 +30,8 @@ private HttpContext HttpContext public JsonApiContentNegotiator(IJsonApiOptions options, IHttpContextAccessor httpContextAccessor) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(httpContextAccessor); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(httpContextAccessor); _options = options; _httpContextAccessor = httpContextAccessor; diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiInputFormatter.cs b/src/JsonApiDotNetCore/Middleware/JsonApiInputFormatter.cs index 9988d0dcaf..008d5fd6dd 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiInputFormatter.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiInputFormatter.cs @@ -10,7 +10,7 @@ public sealed class JsonApiInputFormatter : IJsonApiInputFormatter /// public bool CanRead(InputFormatterContext context) { - ArgumentGuard.NotNull(context); + ArgumentNullException.ThrowIfNull(context); return context.HttpContext.IsJsonApiRequest(); } @@ -18,7 +18,7 @@ public bool CanRead(InputFormatterContext context) /// public async Task ReadAsync(InputFormatterContext context) { - ArgumentGuard.NotNull(context); + ArgumentNullException.ThrowIfNull(context); var reader = context.HttpContext.RequestServices.GetRequiredService(); diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiMediaType.cs b/src/JsonApiDotNetCore/Middleware/JsonApiMediaType.cs index 57e5c40e5e..d9661abffd 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiMediaType.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiMediaType.cs @@ -33,14 +33,14 @@ public sealed class JsonApiMediaType : IEquatable public JsonApiMediaType(IReadOnlySet extensions) { - ArgumentGuard.NotNull(extensions); + ArgumentNullException.ThrowIfNull(extensions); Extensions = extensions; } public JsonApiMediaType(IEnumerable extensions) { - ArgumentGuard.NotNull(extensions); + ArgumentNullException.ThrowIfNull(extensions); Extensions = extensions.ToHashSet().AsReadOnly(); } diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiMediaTypeExtension.cs b/src/JsonApiDotNetCore/Middleware/JsonApiMediaTypeExtension.cs index 0e07eb40e0..f35a613dc1 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiMediaTypeExtension.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiMediaTypeExtension.cs @@ -15,7 +15,7 @@ public sealed class JsonApiMediaTypeExtension : IEquatable logger) { - ArgumentGuard.NotNull(httpContextAccessor); - ArgumentGuard.NotNull(controllerResourceMapping); - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(contentNegotiator); - ArgumentGuard.NotNull(logger); + ArgumentNullException.ThrowIfNull(httpContextAccessor); + ArgumentNullException.ThrowIfNull(controllerResourceMapping); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(contentNegotiator); + ArgumentNullException.ThrowIfNull(logger); _next = next; _controllerResourceMapping = controllerResourceMapping; @@ -50,8 +50,8 @@ public JsonApiMiddleware(RequestDelegate? next, IHttpContextAccessor httpContext public async Task InvokeAsync(HttpContext httpContext, IJsonApiRequest request) { - ArgumentGuard.NotNull(httpContext); - ArgumentGuard.NotNull(request); + ArgumentNullException.ThrowIfNull(httpContext); + ArgumentNullException.ThrowIfNull(request); using (CodeTimingSessionManager.Current.Measure("JSON:API middleware")) { diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiOutputFormatter.cs b/src/JsonApiDotNetCore/Middleware/JsonApiOutputFormatter.cs index 80d7863251..1f6de39b8b 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiOutputFormatter.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiOutputFormatter.cs @@ -10,7 +10,7 @@ public sealed class JsonApiOutputFormatter : IJsonApiOutputFormatter /// public bool CanWriteResult(OutputFormatterCanWriteContext context) { - ArgumentGuard.NotNull(context); + ArgumentNullException.ThrowIfNull(context); return context.HttpContext.IsJsonApiRequest(); } @@ -18,7 +18,7 @@ public bool CanWriteResult(OutputFormatterCanWriteContext context) /// public async Task WriteAsync(OutputFormatterWriteContext context) { - ArgumentGuard.NotNull(context); + ArgumentNullException.ThrowIfNull(context); var writer = context.HttpContext.RequestServices.GetRequiredService(); await writer.WriteAsync(context.Object, context.HttpContext); diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiRequest.cs b/src/JsonApiDotNetCore/Middleware/JsonApiRequest.cs index bba58aaab5..4f382ec329 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiRequest.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiRequest.cs @@ -43,7 +43,7 @@ public sealed class JsonApiRequest : IJsonApiRequest /// public void CopyFrom(IJsonApiRequest other) { - ArgumentGuard.NotNull(other); + ArgumentNullException.ThrowIfNull(other); Kind = other.Kind; PrimaryId = other.PrimaryId; diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs b/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs index 8403109d19..027775df29 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs @@ -41,10 +41,10 @@ public sealed partial class JsonApiRoutingConvention : IJsonApiRoutingConvention public JsonApiRoutingConvention(IJsonApiOptions options, IResourceGraph resourceGraph, IJsonApiEndpointFilter jsonApiEndpointFilter, ILogger logger) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(jsonApiEndpointFilter); - ArgumentGuard.NotNull(logger); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(jsonApiEndpointFilter); + ArgumentNullException.ThrowIfNull(logger); _options = options; _resourceGraph = resourceGraph; @@ -69,7 +69,7 @@ public JsonApiRoutingConvention(IJsonApiOptions options, IResourceGraph resource /// public void Apply(ApplicationModel application) { - ArgumentGuard.NotNull(application); + ArgumentNullException.ThrowIfNull(application); foreach (ControllerModel controller in application.Controllers) { diff --git a/src/JsonApiDotNetCore/Queries/EvaluatedIncludeCache.cs b/src/JsonApiDotNetCore/Queries/EvaluatedIncludeCache.cs index ea54da96af..72a311d246 100644 --- a/src/JsonApiDotNetCore/Queries/EvaluatedIncludeCache.cs +++ b/src/JsonApiDotNetCore/Queries/EvaluatedIncludeCache.cs @@ -11,7 +11,7 @@ internal sealed class EvaluatedIncludeCache : IEvaluatedIncludeCache public EvaluatedIncludeCache(IEnumerable constraintProviders) { - ArgumentGuard.NotNull(constraintProviders); + ArgumentNullException.ThrowIfNull(constraintProviders); _constraintProviders = constraintProviders as IQueryConstraintProvider[] ?? constraintProviders.ToArray(); } @@ -19,7 +19,7 @@ public EvaluatedIncludeCache(IEnumerable constraintPro /// public void Set(IncludeExpression include) { - ArgumentGuard.NotNull(include); + ArgumentNullException.ThrowIfNull(include); _include = include; _isAssigned = true; diff --git a/src/JsonApiDotNetCore/Queries/ExpressionInScope.cs b/src/JsonApiDotNetCore/Queries/ExpressionInScope.cs index 6ac6f75059..4cab3e203b 100644 --- a/src/JsonApiDotNetCore/Queries/ExpressionInScope.cs +++ b/src/JsonApiDotNetCore/Queries/ExpressionInScope.cs @@ -15,7 +15,7 @@ public class ExpressionInScope public ExpressionInScope(ResourceFieldChainExpression? scope, QueryExpression expression) { - ArgumentGuard.NotNull(expression); + ArgumentNullException.ThrowIfNull(expression); Scope = scope; Expression = expression; diff --git a/src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs index dfa7536b03..306a98d1aa 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs @@ -28,7 +28,7 @@ public class AnyExpression : FilterExpression public AnyExpression(ResourceFieldChainExpression targetAttribute, IImmutableSet constants) { - ArgumentGuard.NotNull(targetAttribute); + ArgumentNullException.ThrowIfNull(targetAttribute); ArgumentGuard.NotNullNorEmpty(constants); TargetAttribute = targetAttribute; diff --git a/src/JsonApiDotNetCore/Queries/Expressions/ComparisonExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/ComparisonExpression.cs index 9259560776..b768f556ce 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/ComparisonExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/ComparisonExpression.cs @@ -40,8 +40,8 @@ public class ComparisonExpression : FilterExpression public ComparisonExpression(ComparisonOperator @operator, QueryExpression left, QueryExpression right) { - ArgumentGuard.NotNull(left); - ArgumentGuard.NotNull(right); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); Operator = @operator; Left = left; diff --git a/src/JsonApiDotNetCore/Queries/Expressions/CountExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/CountExpression.cs index 960cf6371b..f79c49af1b 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/CountExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/CountExpression.cs @@ -26,7 +26,7 @@ public class CountExpression : FunctionExpression public CountExpression(ResourceFieldChainExpression targetCollection) { - ArgumentGuard.NotNull(targetCollection); + ArgumentNullException.ThrowIfNull(targetCollection); TargetCollection = targetCollection; } diff --git a/src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs index 709fd60916..5c40039d4e 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs @@ -32,7 +32,7 @@ public class HasExpression : FilterExpression public HasExpression(ResourceFieldChainExpression targetCollection, FilterExpression? filter) { - ArgumentGuard.NotNull(targetCollection); + ArgumentNullException.ThrowIfNull(targetCollection); TargetCollection = targetCollection; Filter = filter; diff --git a/src/JsonApiDotNetCore/Queries/Expressions/IncludeChainConverter.cs b/src/JsonApiDotNetCore/Queries/Expressions/IncludeChainConverter.cs index 5915886e72..c729c692b9 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/IncludeChainConverter.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/IncludeChainConverter.cs @@ -29,7 +29,7 @@ internal sealed class IncludeChainConverter /// public IReadOnlyCollection GetRelationshipChains(IncludeExpression include) { - ArgumentGuard.NotNull(include); + ArgumentNullException.ThrowIfNull(include); if (include.Elements.Count == 0) { diff --git a/src/JsonApiDotNetCore/Queries/Expressions/IncludeElementExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/IncludeElementExpression.cs index b67ece4379..9e98deefe3 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/IncludeElementExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/IncludeElementExpression.cs @@ -32,8 +32,8 @@ public IncludeElementExpression(RelationshipAttribute relationship) public IncludeElementExpression(RelationshipAttribute relationship, IImmutableSet children) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(children); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(children); Relationship = relationship; Children = children; diff --git a/src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs index c916aff3bc..e2f68ee8ec 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs @@ -41,7 +41,7 @@ public class IsTypeExpression : FilterExpression public IsTypeExpression(ResourceFieldChainExpression? targetToOneRelationship, ResourceType derivedType, FilterExpression? child) { - ArgumentGuard.NotNull(derivedType); + ArgumentNullException.ThrowIfNull(derivedType); TargetToOneRelationship = targetToOneRelationship; DerivedType = derivedType; diff --git a/src/JsonApiDotNetCore/Queries/Expressions/LiteralConstantExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/LiteralConstantExpression.cs index 1592aadcfd..50c3b2cd54 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/LiteralConstantExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/LiteralConstantExpression.cs @@ -24,8 +24,8 @@ public LiteralConstantExpression(object typedValue) public LiteralConstantExpression(object typedValue, string stringValue) { - ArgumentGuard.NotNull(typedValue); - ArgumentGuard.NotNull(stringValue); + ArgumentNullException.ThrowIfNull(typedValue); + ArgumentNullException.ThrowIfNull(stringValue); TypedValue = typedValue; _stringValue = stringValue; @@ -33,7 +33,7 @@ public LiteralConstantExpression(object typedValue, string stringValue) private static string? GetStringValue(object typedValue) { - ArgumentGuard.NotNull(typedValue); + ArgumentNullException.ThrowIfNull(typedValue); return typedValue is IFormattable cultureAwareValue ? cultureAwareValue.ToString(null, CultureInfo.InvariantCulture) : typedValue.ToString(); } diff --git a/src/JsonApiDotNetCore/Queries/Expressions/LogicalExpression.cs b/src/JsonApiDotNetCore/Queries/Expressions/LogicalExpression.cs index f1a9ba8c1c..416303b06b 100644 --- a/src/JsonApiDotNetCore/Queries/Expressions/LogicalExpression.cs +++ b/src/JsonApiDotNetCore/Queries/Expressions/LogicalExpression.cs @@ -37,7 +37,7 @@ public LogicalExpression(LogicalOperator @operator, params FilterExpression[] te public LogicalExpression(LogicalOperator @operator, IImmutableList terms) { - ArgumentGuard.NotNull(terms); + ArgumentNullException.ThrowIfNull(terms); if (terms.Count < 2) { @@ -50,7 +50,7 @@ public LogicalExpression(LogicalOperator @operator, IImmutableList> fieldSelector, IResourceGraph resourceGraph) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(fieldSelector); - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(fieldSelector); + ArgumentNullException.ThrowIfNull(resourceGraph); SparseFieldSetExpression? newSparseFieldSet = sparseFieldSet; @@ -42,8 +42,8 @@ public static class SparseFieldSetExpressionExtensions Expression> fieldSelector, IResourceGraph resourceGraph) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(fieldSelector); - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(fieldSelector); + ArgumentNullException.ThrowIfNull(resourceGraph); SparseFieldSetExpression? newSparseFieldSet = sparseFieldSet; diff --git a/src/JsonApiDotNetCore/Queries/FieldSelection.cs b/src/JsonApiDotNetCore/Queries/FieldSelection.cs index 53cf38268e..b929db2c80 100644 --- a/src/JsonApiDotNetCore/Queries/FieldSelection.cs +++ b/src/JsonApiDotNetCore/Queries/FieldSelection.cs @@ -23,7 +23,7 @@ public IReadOnlySet GetResourceTypes() public FieldSelectors GetOrCreateSelectors(ResourceType resourceType) #pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); if (!ContainsKey(resourceType)) { diff --git a/src/JsonApiDotNetCore/Queries/FieldSelectors.cs b/src/JsonApiDotNetCore/Queries/FieldSelectors.cs index 63415cfffc..d9ab815638 100644 --- a/src/JsonApiDotNetCore/Queries/FieldSelectors.cs +++ b/src/JsonApiDotNetCore/Queries/FieldSelectors.cs @@ -30,21 +30,21 @@ public bool ContainsOnlyRelationships public bool ContainsField(ResourceFieldAttribute field) { - ArgumentGuard.NotNull(field); + ArgumentNullException.ThrowIfNull(field); return ContainsKey(field); } public void IncludeAttribute(AttrAttribute attribute) { - ArgumentGuard.NotNull(attribute); + ArgumentNullException.ThrowIfNull(attribute); this[attribute] = null; } public void IncludeAttributes(IEnumerable attributes) { - ArgumentGuard.NotNull(attributes); + ArgumentNullException.ThrowIfNull(attributes); foreach (AttrAttribute attribute in attributes) { @@ -54,8 +54,8 @@ public void IncludeAttributes(IEnumerable attributes) public void IncludeRelationship(RelationshipAttribute relationship, QueryLayer queryLayer) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(queryLayer); this[relationship] = queryLayer; } diff --git a/src/JsonApiDotNetCore/Queries/Parsing/FilterParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/FilterParser.cs index fd300c0431..f89bf3dc39 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/FilterParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/FilterParser.cs @@ -54,7 +54,7 @@ protected ResourceType ResourceTypeInScope public FilterParser(IResourceFactory resourceFactory) { - ArgumentGuard.NotNull(resourceFactory); + ArgumentNullException.ThrowIfNull(resourceFactory); _resourceFactory = resourceFactory; } @@ -62,7 +62,7 @@ public FilterParser(IResourceFactory resourceFactory) /// public FilterExpression Parse(string source, ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Tokenize(source); @@ -83,7 +83,7 @@ public FilterExpression Parse(string source, ResourceType resourceType) protected virtual bool IsFunction(string name) { - ArgumentGuard.NotNullNorEmpty(name); + ArgumentException.ThrowIfNullOrEmpty(name); return name == Keywords.Count || FilterKeywords.Contains(name); } @@ -179,7 +179,7 @@ protected virtual NotExpression ParseNot() protected virtual LogicalExpression ParseLogical(string operatorName) { - ArgumentGuard.NotNullNorEmpty(operatorName); + ArgumentException.ThrowIfNullOrEmpty(operatorName); EatText(operatorName); EatSingleCharacterToken(TokenKind.OpenParen); @@ -210,7 +210,7 @@ protected virtual LogicalExpression ParseLogical(string operatorName) protected virtual ComparisonExpression ParseComparison(string operatorName) { - ArgumentGuard.NotNullNorEmpty(operatorName); + ArgumentException.ThrowIfNullOrEmpty(operatorName); var comparisonOperator = Enum.Parse(operatorName.Pascalize()); @@ -315,7 +315,7 @@ private QueryExpression ParseTypedComparisonRightTerm(Type leftType, ConstantVal protected virtual MatchTextExpression ParseTextMatch(string operatorName) { - ArgumentGuard.NotNullNorEmpty(operatorName); + ArgumentException.ThrowIfNullOrEmpty(operatorName); EatText(operatorName); EatSingleCharacterToken(TokenKind.OpenParen); @@ -522,7 +522,7 @@ private NullConstantExpression ParseNull() protected virtual ConstantValueConverter GetConstantValueConverterForType(Type destinationType) { - ArgumentGuard.NotNull(destinationType); + ArgumentNullException.ThrowIfNull(destinationType); return (stringValue, position) => { @@ -566,7 +566,7 @@ private object DeObfuscateStringId(ResourceType resourceType, string stringId) protected override void ValidateField(ResourceFieldAttribute field, int position) { - ArgumentGuard.NotNull(field); + ArgumentNullException.ThrowIfNull(field); if (field.IsFilterBlocked()) { @@ -580,7 +580,7 @@ protected override void ValidateField(ResourceFieldAttribute field, int position /// protected IDisposable InScopeOfResourceType(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); _resourceTypeStack.Push(resourceType); return new PopResourceTypeOnDispose(_resourceTypeStack); diff --git a/src/JsonApiDotNetCore/Queries/Parsing/IncludeParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/IncludeParser.cs index 6afa8a0698..eb328f3183 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/IncludeParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/IncludeParser.cs @@ -17,7 +17,7 @@ public class IncludeParser : QueryExpressionParser, IIncludeParser public IncludeParser(IJsonApiOptions options) { - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(options); _options = options; } @@ -25,7 +25,7 @@ public IncludeParser(IJsonApiOptions options) /// public IncludeExpression Parse(string source, ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Tokenize(source); @@ -39,8 +39,8 @@ public IncludeExpression Parse(string source, ResourceType resourceType) protected virtual IncludeExpression ParseInclude(string source, ResourceType resourceType) { - ArgumentGuard.NotNull(source); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(resourceType); var treeRoot = IncludeTreeNode.CreateRoot(resourceType); bool isAtStart = true; @@ -307,7 +307,7 @@ private sealed class HiddenRootRelationshipAttribute : RelationshipAttribute { public HiddenRootRelationshipAttribute(ResourceType rightType) { - ArgumentGuard.NotNull(rightType); + ArgumentNullException.ThrowIfNull(rightType); RightType = rightType; PublicName = "<>"; diff --git a/src/JsonApiDotNetCore/Queries/Parsing/PaginationParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/PaginationParser.cs index fff06ed3ec..669fba7b9c 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/PaginationParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/PaginationParser.cs @@ -13,7 +13,7 @@ public class PaginationParser : QueryExpressionParser, IPaginationParser /// public PaginationQueryStringValueExpression Parse(string source, ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Tokenize(source); @@ -26,7 +26,7 @@ public PaginationQueryStringValueExpression Parse(string source, ResourceType re protected virtual PaginationQueryStringValueExpression ParsePagination(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); ImmutableArray.Builder elementsBuilder = ImmutableArray.CreateBuilder(); @@ -47,7 +47,7 @@ protected virtual PaginationQueryStringValueExpression ParsePagination(ResourceT protected virtual PaginationElementQueryStringValueExpression ParsePaginationElement(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); int position = GetNextTokenPositionOrEnd(); int? number = TryParseNumber(); diff --git a/src/JsonApiDotNetCore/Queries/Parsing/QueryExpressionParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/QueryExpressionParser.cs index fc93c3fb81..772be38530 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/QueryExpressionParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/QueryExpressionParser.cs @@ -43,7 +43,7 @@ protected virtual void ValidateField(ResourceFieldAttribute field, int position) /// protected virtual void Tokenize(string source) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); var tokenizer = new QueryTokenizer(source); TokenStack = new Stack(tokenizer.EnumerateTokens().Reverse()); @@ -56,8 +56,8 @@ protected virtual void Tokenize(string source) protected ResourceFieldChainExpression ParseFieldChain(FieldChainPattern pattern, FieldChainPatternMatchOptions options, ResourceType resourceType, string? alternativeErrorMessage) { - ArgumentGuard.NotNull(pattern); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(resourceType); int startPosition = GetNextTokenPositionOrEnd(); @@ -120,7 +120,7 @@ private string EatFieldChain(string? alternativeErrorMessage) /// protected void EatText(string text) { - ArgumentGuard.NotNull(text); + ArgumentNullException.ThrowIfNull(text); if (!TokenStack.TryPop(out Token? token) || token.Kind != TokenKind.Text || token.Value != text) { @@ -162,7 +162,7 @@ protected int GetNextTokenPositionOrEnd() /// protected int GetRelativePositionOfLastFieldInChain(ResourceFieldChainExpression fieldChain) { - ArgumentGuard.NotNull(fieldChain); + ArgumentNullException.ThrowIfNull(fieldChain); int position = 0; diff --git a/src/JsonApiDotNetCore/Queries/Parsing/QueryParseException.cs b/src/JsonApiDotNetCore/Queries/Parsing/QueryParseException.cs index 8136fb476e..4f63f45e24 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/QueryParseException.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/QueryParseException.cs @@ -28,7 +28,7 @@ public QueryParseException(string message, int position, Exception innerExceptio public string GetMessageWithPosition(string sourceText) { - ArgumentGuard.NotNull(sourceText); + ArgumentNullException.ThrowIfNull(sourceText); if (Position < 0) { diff --git a/src/JsonApiDotNetCore/Queries/Parsing/QueryStringParameterScopeParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/QueryStringParameterScopeParser.cs index 8b7b80f70c..dfb98dc612 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/QueryStringParameterScopeParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/QueryStringParameterScopeParser.cs @@ -12,8 +12,8 @@ public class QueryStringParameterScopeParser : QueryExpressionParser, IQueryStri /// public QueryStringParameterScopeExpression Parse(string source, ResourceType resourceType, FieldChainPattern pattern, FieldChainPatternMatchOptions options) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(pattern); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(pattern); Tokenize(source); @@ -27,8 +27,8 @@ public QueryStringParameterScopeExpression Parse(string source, ResourceType res protected virtual QueryStringParameterScopeExpression ParseQueryStringParameterScope(ResourceType resourceType, FieldChainPattern pattern, FieldChainPatternMatchOptions options) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(pattern); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(pattern); int position = GetNextTokenPositionOrEnd(); diff --git a/src/JsonApiDotNetCore/Queries/Parsing/QueryTokenizer.cs b/src/JsonApiDotNetCore/Queries/Parsing/QueryTokenizer.cs index c73a8042d1..0c5f634375 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/QueryTokenizer.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/QueryTokenizer.cs @@ -26,7 +26,7 @@ public sealed class QueryTokenizer public QueryTokenizer(string source) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); _source = source; } diff --git a/src/JsonApiDotNetCore/Queries/Parsing/SortParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/SortParser.cs index db622873d2..e8df9b4a88 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/SortParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/SortParser.cs @@ -14,7 +14,7 @@ public class SortParser : QueryExpressionParser, ISortParser /// public SortExpression Parse(string source, ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Tokenize(source); @@ -27,7 +27,7 @@ public SortExpression Parse(string source, ResourceType resourceType) protected virtual SortExpression ParseSort(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); SortElementExpression firstElement = ParseSortElement(resourceType); @@ -47,7 +47,7 @@ protected virtual SortExpression ParseSort(ResourceType resourceType) protected virtual SortElementExpression ParseSortElement(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); bool isAscending = true; @@ -99,14 +99,14 @@ protected virtual SortElementExpression ParseSortElement(ResourceType resourceTy protected virtual bool IsFunction(string name) { - ArgumentGuard.NotNullNorEmpty(name); + ArgumentException.ThrowIfNullOrEmpty(name); return name == Keywords.Count; } protected virtual FunctionExpression ParseFunction(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); if (TokenStack.TryPeek(out Token? nextToken) && nextToken.Kind == TokenKind.Text) { @@ -138,7 +138,7 @@ private CountExpression ParseCount(ResourceType resourceType) protected override void ValidateField(ResourceFieldAttribute field, int position) { - ArgumentGuard.NotNull(field); + ArgumentNullException.ThrowIfNull(field); if (field is AttrAttribute attribute && !attribute.Capabilities.HasFlag(AttrCapabilities.AllowSort)) { diff --git a/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldSetParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldSetParser.cs index d4ac0ff921..9bf6a89daa 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldSetParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldSetParser.cs @@ -14,7 +14,7 @@ public class SparseFieldSetParser : QueryExpressionParser, ISparseFieldSetParser /// public SparseFieldSetExpression? Parse(string source, ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Tokenize(source); @@ -27,7 +27,7 @@ public class SparseFieldSetParser : QueryExpressionParser, ISparseFieldSetParser protected virtual SparseFieldSetExpression? ParseSparseFieldSet(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); ImmutableHashSet.Builder fieldSetBuilder = ImmutableHashSet.CreateBuilder(); @@ -50,7 +50,7 @@ public class SparseFieldSetParser : QueryExpressionParser, ISparseFieldSetParser protected override void ValidateField(ResourceFieldAttribute field, int position) { - ArgumentGuard.NotNull(field); + ArgumentNullException.ThrowIfNull(field); if (field.IsViewBlocked()) { diff --git a/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldTypeParser.cs b/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldTypeParser.cs index e24ce9f90e..00c5c6a525 100644 --- a/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldTypeParser.cs +++ b/src/JsonApiDotNetCore/Queries/Parsing/SparseFieldTypeParser.cs @@ -11,7 +11,7 @@ public class SparseFieldTypeParser : QueryExpressionParser, ISparseFieldTypePars public SparseFieldTypeParser(IResourceGraph resourceGraph) { - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(resourceGraph); _resourceGraph = resourceGraph; } diff --git a/src/JsonApiDotNetCore/Queries/QueryLayer.cs b/src/JsonApiDotNetCore/Queries/QueryLayer.cs index e30de0ef03..1ff8e34dcf 100644 --- a/src/JsonApiDotNetCore/Queries/QueryLayer.cs +++ b/src/JsonApiDotNetCore/Queries/QueryLayer.cs @@ -21,7 +21,7 @@ public sealed class QueryLayer public QueryLayer(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); ResourceType = resourceType; } diff --git a/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs b/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs index 0c704d0013..141800cdfd 100644 --- a/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs +++ b/src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs @@ -26,13 +26,13 @@ public QueryLayerComposer(IEnumerable constraintProvid IJsonApiOptions options, IPaginationContext paginationContext, ITargetedFields targetedFields, IEvaluatedIncludeCache evaluatedIncludeCache, ISparseFieldSetCache sparseFieldSetCache) { - ArgumentGuard.NotNull(constraintProviders); - ArgumentGuard.NotNull(resourceDefinitionAccessor); - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(paginationContext); - ArgumentGuard.NotNull(targetedFields); - ArgumentGuard.NotNull(evaluatedIncludeCache); - ArgumentGuard.NotNull(sparseFieldSetCache); + ArgumentNullException.ThrowIfNull(constraintProviders); + ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(paginationContext); + ArgumentNullException.ThrowIfNull(targetedFields); + ArgumentNullException.ThrowIfNull(evaluatedIncludeCache); + ArgumentNullException.ThrowIfNull(sparseFieldSetCache); _constraintProviders = constraintProviders as IQueryConstraintProvider[] ?? constraintProviders.ToArray(); _resourceDefinitionAccessor = resourceDefinitionAccessor; @@ -66,7 +66,7 @@ public QueryLayerComposer(IEnumerable constraintProvid /// public FilterExpression? GetSecondaryFilterFromConstraints([DisallowNull] TId primaryId, HasManyAttribute hasManyRelationship) { - ArgumentGuard.NotNull(hasManyRelationship); + ArgumentNullException.ThrowIfNull(hasManyRelationship); if (hasManyRelationship.InverseNavigationProperty == null) { @@ -133,7 +133,7 @@ private static HasExpression GetInverseHasManyRelationshipFilter([DisallowN /// public QueryLayer ComposeFromConstraints(ResourceType requestResourceType) { - ArgumentGuard.NotNull(requestResourceType); + ArgumentNullException.ThrowIfNull(requestResourceType); ImmutableArray constraints = [.. _constraintProviders.SelectMany(provider => provider.GetConstraints())]; @@ -269,7 +269,7 @@ private static ImmutableHashSet ApplyIncludeElementUpd /// public QueryLayer ComposeForGetById([DisallowNull] TId id, ResourceType primaryResourceType, TopFieldSelection fieldSelection) { - ArgumentGuard.NotNull(primaryResourceType); + ArgumentNullException.ThrowIfNull(primaryResourceType); AttrAttribute idAttribute = GetIdAttribute(primaryResourceType); @@ -297,7 +297,7 @@ public QueryLayer ComposeForGetById([DisallowNull] TId id, ResourceType pri /// public QueryLayer ComposeSecondaryLayerForRelationship(ResourceType secondaryResourceType) { - ArgumentGuard.NotNull(secondaryResourceType); + ArgumentNullException.ThrowIfNull(secondaryResourceType); QueryLayer secondaryLayer = ComposeFromConstraints(secondaryResourceType); secondaryLayer.Selection = GetSelectionForRelationship(secondaryResourceType); @@ -321,9 +321,9 @@ private FieldSelection GetSelectionForRelationship(ResourceType secondaryResourc public QueryLayer WrapLayerForSecondaryEndpoint(QueryLayer secondaryLayer, ResourceType primaryResourceType, [DisallowNull] TId primaryId, RelationshipAttribute relationship) { - ArgumentGuard.NotNull(secondaryLayer); - ArgumentGuard.NotNull(primaryResourceType); - ArgumentGuard.NotNull(relationship); + ArgumentNullException.ThrowIfNull(secondaryLayer); + ArgumentNullException.ThrowIfNull(primaryResourceType); + ArgumentNullException.ThrowIfNull(relationship); IncludeExpression? innerInclude = secondaryLayer.Include; secondaryLayer.Include = null; @@ -383,7 +383,7 @@ private IncludeExpression RewriteIncludeForSecondaryEndpoint(IncludeExpression? /// public QueryLayer ComposeForUpdate([DisallowNull] TId id, ResourceType primaryResourceType) { - ArgumentGuard.NotNull(primaryResourceType); + ArgumentNullException.ThrowIfNull(primaryResourceType); ImmutableHashSet includeElements = _targetedFields.Relationships .Select(relationship => new IncludeElementExpression(relationship)).ToImmutableHashSet(); @@ -403,7 +403,7 @@ public QueryLayer ComposeForUpdate([DisallowNull] TId id, ResourceType prim /// public IEnumerable<(QueryLayer, RelationshipAttribute)> ComposeForGetTargetedSecondaryResourceIds(IIdentifiable primaryResource) { - ArgumentGuard.NotNull(primaryResource); + ArgumentNullException.ThrowIfNull(primaryResource); foreach (RelationshipAttribute relationship in _targetedFields.Relationships) { @@ -421,8 +421,8 @@ public QueryLayer ComposeForUpdate([DisallowNull] TId id, ResourceType prim /// public QueryLayer ComposeForGetRelationshipRightIds(RelationshipAttribute relationship, ICollection rightResourceIds) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(rightResourceIds); AttrAttribute rightIdAttribute = GetIdAttribute(relationship.RightType); @@ -446,8 +446,8 @@ public QueryLayer ComposeForGetRelationshipRightIds(RelationshipAttribute relati /// public QueryLayer ComposeForHasMany(HasManyAttribute hasManyRelationship, [DisallowNull] TId leftId, ICollection rightResourceIds) { - ArgumentGuard.NotNull(hasManyRelationship); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(hasManyRelationship); + ArgumentNullException.ThrowIfNull(rightResourceIds); AttrAttribute leftIdAttribute = GetIdAttribute(hasManyRelationship.LeftType); AttrAttribute rightIdAttribute = GetIdAttribute(hasManyRelationship.RightType); @@ -482,16 +482,16 @@ public QueryLayer ComposeForHasMany(HasManyAttribute hasManyRelationship, [ protected virtual IImmutableSet GetIncludeElements(IImmutableSet includeElements, ResourceType resourceType) { - ArgumentGuard.NotNull(includeElements); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(includeElements); + ArgumentNullException.ThrowIfNull(resourceType); return _resourceDefinitionAccessor.OnApplyIncludes(resourceType, includeElements); } protected virtual FilterExpression? GetFilter(IReadOnlyCollection expressionsInScope, ResourceType resourceType) { - ArgumentGuard.NotNull(expressionsInScope); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(expressionsInScope); + ArgumentNullException.ThrowIfNull(resourceType); FilterExpression[] filters = expressionsInScope.OfType().ToArray(); FilterExpression? filter = LogicalExpression.Compose(LogicalOperator.And, filters); @@ -501,8 +501,8 @@ protected virtual IImmutableSet GetIncludeElements(IIm protected virtual SortExpression GetSort(IReadOnlyCollection expressionsInScope, ResourceType resourceType) { - ArgumentGuard.NotNull(expressionsInScope); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(expressionsInScope); + ArgumentNullException.ThrowIfNull(resourceType); SortExpression? sort = expressionsInScope.OfType().FirstOrDefault(); @@ -520,8 +520,8 @@ protected virtual SortExpression GetSort(IReadOnlyCollection ex protected virtual PaginationExpression GetPagination(IReadOnlyCollection expressionsInScope, ResourceType resourceType) { - ArgumentGuard.NotNull(expressionsInScope); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(expressionsInScope); + ArgumentNullException.ThrowIfNull(resourceType); PaginationExpression? pagination = expressionsInScope.OfType().FirstOrDefault(); @@ -536,7 +536,7 @@ protected virtual PaginationExpression GetPagination(IReadOnlyCollection public LambdaScope CreateScope(Type elementType, Expression? accessorExpression = null) { - ArgumentGuard.NotNull(elementType); + ArgumentNullException.ThrowIfNull(elementType); string parameterName = elementType.Name.Camelize(); parameterName = EnsureUniqueName(parameterName); @@ -48,7 +48,7 @@ private string EnsureUniqueName(string name) internal void Release(LambdaScope lambdaScope) { - ArgumentGuard.NotNull(lambdaScope); + ArgumentNullException.ThrowIfNull(lambdaScope); _namesInScope.Remove(lambdaScope.Parameter.Name!); } diff --git a/src/JsonApiDotNetCore/Queries/QueryableBuilding/OrderClauseBuilder.cs b/src/JsonApiDotNetCore/Queries/QueryableBuilding/OrderClauseBuilder.cs index ab37d2aff1..6528d63ff8 100644 --- a/src/JsonApiDotNetCore/Queries/QueryableBuilding/OrderClauseBuilder.cs +++ b/src/JsonApiDotNetCore/Queries/QueryableBuilding/OrderClauseBuilder.cs @@ -10,7 +10,7 @@ public class OrderClauseBuilder : QueryClauseBuilder, IOrderClauseBuilder { public virtual Expression ApplyOrderBy(SortExpression expression, QueryClauseBuilderContext context) { - ArgumentGuard.NotNull(expression); + ArgumentNullException.ThrowIfNull(expression); return Visit(expression, context); } diff --git a/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryClauseBuilderContext.cs b/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryClauseBuilderContext.cs index b218b09ca6..6344b91cb8 100644 --- a/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryClauseBuilderContext.cs +++ b/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryClauseBuilderContext.cs @@ -54,13 +54,13 @@ public sealed class QueryClauseBuilderContext public QueryClauseBuilderContext(Expression source, ResourceType resourceType, Type extensionType, IReadOnlyModel entityModel, LambdaScopeFactory lambdaScopeFactory, LambdaScope lambdaScope, IQueryableBuilder queryableBuilder, object? state) { - ArgumentGuard.NotNull(source); - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(extensionType); - ArgumentGuard.NotNull(entityModel); - ArgumentGuard.NotNull(lambdaScopeFactory); - ArgumentGuard.NotNull(lambdaScope); - ArgumentGuard.NotNull(queryableBuilder); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(extensionType); + ArgumentNullException.ThrowIfNull(entityModel); + ArgumentNullException.ThrowIfNull(lambdaScopeFactory); + ArgumentNullException.ThrowIfNull(lambdaScope); + ArgumentNullException.ThrowIfNull(queryableBuilder); AssertSameType(source.Type, resourceType); Source = source; @@ -86,14 +86,14 @@ private static void AssertSameType(Type sourceType, ResourceType resourceType) public QueryClauseBuilderContext WithSource(Expression source) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); return new QueryClauseBuilderContext(source, ResourceType, ExtensionType, EntityModel, LambdaScopeFactory, LambdaScope, QueryableBuilder, State); } public QueryClauseBuilderContext WithLambdaScope(LambdaScope lambdaScope) { - ArgumentGuard.NotNull(lambdaScope); + ArgumentNullException.ThrowIfNull(lambdaScope); return new QueryClauseBuilderContext(Source, ResourceType, ExtensionType, EntityModel, LambdaScopeFactory, lambdaScope, QueryableBuilder, State); } diff --git a/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryLayerIncludeConverter.cs b/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryLayerIncludeConverter.cs index 9c4351f0f7..5d4eec3e31 100644 --- a/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryLayerIncludeConverter.cs +++ b/src/JsonApiDotNetCore/Queries/QueryableBuilding/QueryLayerIncludeConverter.cs @@ -12,7 +12,7 @@ public sealed class QueryLayerIncludeConverter : QueryExpressionVisitor constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor) { - ArgumentGuard.NotNull(constraintProviders); - ArgumentGuard.NotNull(resourceDefinitionAccessor); + ArgumentNullException.ThrowIfNull(constraintProviders); + ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor); _resourceDefinitionAccessor = resourceDefinitionAccessor; _lazySourceTable = new Lazy>>(() => BuildSourceTable(constraintProviders)); @@ -71,7 +71,7 @@ private static void AddSparseFieldsToSet(IImmutableSet s /// public IImmutableSet GetSparseFieldSetForQuery(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); if (!_visitedTable.TryGetValue(resourceType, out IImmutableSet? outputFields)) { @@ -92,7 +92,7 @@ public IImmutableSet GetSparseFieldSetForQuery(ResourceT /// public IImmutableSet GetIdAttributeSetForRelationshipQuery(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); AttrAttribute idAttribute = resourceType.GetAttributeByPropertyName(nameof(Identifiable.Id)); var inputExpression = new SparseFieldSetExpression(ImmutableHashSet.Create(idAttribute)); @@ -111,7 +111,7 @@ public IImmutableSet GetIdAttributeSetForRelationshipQuery(Resour /// public IImmutableSet GetSparseFieldSetForSerializer(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); if (!_visitedTable.TryGetValue(resourceType, out IImmutableSet? outputFields)) { diff --git a/src/JsonApiDotNetCore/Queries/SystemExpressionBuilder.cs b/src/JsonApiDotNetCore/Queries/SystemExpressionBuilder.cs index f625ee9b4f..72a30a060a 100644 --- a/src/JsonApiDotNetCore/Queries/SystemExpressionBuilder.cs +++ b/src/JsonApiDotNetCore/Queries/SystemExpressionBuilder.cs @@ -20,7 +20,7 @@ internal static class SystemExpressionBuilder public static Expression CloseOver(object value) { - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(value); MethodInfo closeOverClosedMethod = CloseOverOpenMethod.MakeGenericMethod(value.GetType()); return (Expression)closeOverClosedMethod.Invoke(null, [value])!; diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainParser.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainParser.cs index 448b802cec..0bbea6b63f 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainParser.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainParser.cs @@ -7,7 +7,7 @@ internal sealed class FieldChainParser { public IEnumerable Parse(string source) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); if (source.Length > 0) { diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainPattern.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainPattern.cs index fb63c6a03d..e3c15ebdbe 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainPattern.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/FieldChainPattern.cs @@ -144,8 +144,8 @@ public static FieldChainPattern Parse(string pattern) public PatternMatchResult Match(string fieldChain, ResourceType resourceType, FieldChainPatternMatchOptions options = FieldChainPatternMatchOptions.None, ILoggerFactory? loggerFactory = null) { - ArgumentGuard.NotNull(fieldChain); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(fieldChain); + ArgumentNullException.ThrowIfNull(resourceType); ILogger logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger(); var matcher = new PatternMatcher(this, options, logger); diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchState.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchState.cs index fa05753ae8..678850e4c4 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchState.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchState.cs @@ -53,9 +53,9 @@ private MatchState(FieldChainPattern? pattern, ResourceType? resourceType, IImmu public static MatchState Create(FieldChainPattern pattern, string fieldChainText, ResourceType resourceType) { - ArgumentGuard.NotNull(pattern); - ArgumentGuard.NotNull(fieldChainText); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(fieldChainText); + ArgumentNullException.ThrowIfNull(resourceType); try { @@ -77,7 +77,7 @@ public static MatchState Create(FieldChainPattern pattern, string fieldChainText /// public MatchState SuccessMoveForwardOneField(ResourceFieldAttribute matchedValue) { - ArgumentGuard.NotNull(matchedValue); + ArgumentNullException.ThrowIfNull(matchedValue); AssertIsSuccess(this); IImmutableList fieldsMatched = FieldsMatched.Add(matchedValue); diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchTraceScope.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchTraceScope.cs index a4cf569173..5f3dd5f713 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchTraceScope.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/MatchTraceScope.cs @@ -23,8 +23,8 @@ private MatchTraceScope(FieldChainPattern? pattern, bool isEnabled, ILogger logg public static MatchTraceScope CreateRoot(MatchState startState, ILogger logger) { - ArgumentGuard.NotNull(startState); - ArgumentGuard.NotNull(logger); + ArgumentNullException.ThrowIfNull(startState); + ArgumentNullException.ThrowIfNull(logger); bool isEnabled = logger.IsEnabled(LogLevel.Trace); var scope = new MatchTraceScope(startState.Pattern, isEnabled, logger, 0); @@ -40,7 +40,7 @@ public static MatchTraceScope CreateRoot(MatchState startState, ILogger logger) public MatchTraceScope CreateChild(MatchState startState) { - ArgumentGuard.NotNull(startState); + ArgumentNullException.ThrowIfNull(startState); int indentDepth = _indentDepth + 1; FieldChainPattern? patternSegment = startState.Pattern?.WithoutNext(); @@ -57,7 +57,7 @@ public MatchTraceScope CreateChild(MatchState startState) public void LogMatchResult(MatchState resultState) { - ArgumentGuard.NotNull(resultState); + ArgumentNullException.ThrowIfNull(resultState); if (_isEnabled) { @@ -85,7 +85,7 @@ public void LogMatchResult(MatchState resultState) public void LogBacktrackTo(MatchState backtrackState) { - ArgumentGuard.NotNull(backtrackState); + ArgumentNullException.ThrowIfNull(backtrackState); if (_isEnabled) { @@ -97,7 +97,7 @@ public void LogBacktrackTo(MatchState backtrackState) public void SetResult(MatchState endState) { - ArgumentGuard.NotNull(endState); + ArgumentNullException.ThrowIfNull(endState); _endState = endState; } diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternDescriptionFormatter.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternDescriptionFormatter.cs index 841dbb2050..bdd29e3200 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternDescriptionFormatter.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternDescriptionFormatter.cs @@ -11,7 +11,7 @@ internal sealed class PatternDescriptionFormatter public PatternDescriptionFormatter(FieldChainPattern pattern) { - ArgumentGuard.NotNull(pattern); + ArgumentNullException.ThrowIfNull(pattern); _pattern = pattern; } diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatchResult.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatchResult.cs index f32ff953f4..6b9a1d1075 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatchResult.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatchResult.cs @@ -49,14 +49,14 @@ private PatternMatchResult(bool isSuccess, IReadOnlyList internal static PatternMatchResult CreateForSuccess(IReadOnlyList fieldChain) { - ArgumentGuard.NotNull(fieldChain); + ArgumentNullException.ThrowIfNull(fieldChain); return new PatternMatchResult(true, fieldChain, string.Empty, -1, false); } internal static PatternMatchResult CreateForFailure(MatchError error) { - ArgumentGuard.NotNull(error); + ArgumentNullException.ThrowIfNull(error); return new PatternMatchResult(false, Array.Empty(), error.Message, error.Position, error.IsFieldChainError); } diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatcher.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatcher.cs index d05f4e3d12..9a86542533 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatcher.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternMatcher.cs @@ -15,8 +15,8 @@ internal sealed class PatternMatcher public PatternMatcher(FieldChainPattern pattern, FieldChainPatternMatchOptions options, ILogger logger) { - ArgumentGuard.NotNull(pattern); - ArgumentGuard.NotNull(logger); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(logger); _pattern = pattern; _logger = logger; @@ -25,8 +25,8 @@ public PatternMatcher(FieldChainPattern pattern, FieldChainPatternMatchOptions o public PatternMatchResult Match(string fieldChain, ResourceType resourceType) { - ArgumentGuard.NotNull(fieldChain); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(fieldChain); + ArgumentNullException.ThrowIfNull(resourceType); var startState = MatchState.Create(_pattern, fieldChain, resourceType); diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternParser.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternParser.cs index cc0fa0a69e..c6e05fdd4f 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternParser.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternParser.cs @@ -41,7 +41,7 @@ internal sealed class PatternParser public FieldChainPattern Parse(string source) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); _source = source; EnqueueTokens(); diff --git a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternTextFormatter.cs b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternTextFormatter.cs index 6e12ad8481..2fec95b900 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternTextFormatter.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FieldChains/PatternTextFormatter.cs @@ -11,7 +11,7 @@ internal sealed class PatternTextFormatter public PatternTextFormatter(FieldChainPattern pattern) { - ArgumentGuard.NotNull(pattern); + ArgumentNullException.ThrowIfNull(pattern); _pattern = pattern; } diff --git a/src/JsonApiDotNetCore/QueryStrings/FilterQueryStringParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/FilterQueryStringParameterReader.cs index 052e4ac93e..6b85273ddb 100644 --- a/src/JsonApiDotNetCore/QueryStrings/FilterQueryStringParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/FilterQueryStringParameterReader.cs @@ -30,9 +30,9 @@ public FilterQueryStringParameterReader(IQueryStringParameterScopeParser scopePa IResourceGraph resourceGraph, IJsonApiOptions options) : base(request, resourceGraph) { - ArgumentGuard.NotNull(scopeParser); - ArgumentGuard.NotNull(filterParser); - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(scopeParser); + ArgumentNullException.ThrowIfNull(filterParser); + ArgumentNullException.ThrowIfNull(options); _options = options; _scopeParser = scopeParser; @@ -42,7 +42,7 @@ public FilterQueryStringParameterReader(IQueryStringParameterScopeParser scopePa /// public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute) { - ArgumentGuard.NotNull(disableQueryStringAttribute); + ArgumentNullException.ThrowIfNull(disableQueryStringAttribute); return !IsAtomicOperationsRequest && !disableQueryStringAttribute.ContainsParameter(JsonApiQueryStringParameters.Filter); } @@ -50,7 +50,7 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr /// public virtual bool CanRead(string parameterName) { - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterName); bool isNested = parameterName.StartsWith("filter[", StringComparison.Ordinal) && parameterName.EndsWith(']'); return parameterName == "filter" || isNested; diff --git a/src/JsonApiDotNetCore/QueryStrings/IncludeQueryStringParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/IncludeQueryStringParameterReader.cs index 7b3739da8e..55ef25779f 100644 --- a/src/JsonApiDotNetCore/QueryStrings/IncludeQueryStringParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/IncludeQueryStringParameterReader.cs @@ -23,7 +23,7 @@ public class IncludeQueryStringParameterReader : QueryStringParameterReader, IIn public IncludeQueryStringParameterReader(IIncludeParser includeParser, IJsonApiRequest request, IResourceGraph resourceGraph) : base(request, resourceGraph) { - ArgumentGuard.NotNull(includeParser); + ArgumentNullException.ThrowIfNull(includeParser); _includeParser = includeParser; } @@ -31,7 +31,7 @@ public IncludeQueryStringParameterReader(IIncludeParser includeParser, IJsonApiR /// public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute) { - ArgumentGuard.NotNull(disableQueryStringAttribute); + ArgumentNullException.ThrowIfNull(disableQueryStringAttribute); return !IsAtomicOperationsRequest && !disableQueryStringAttribute.ContainsParameter(JsonApiQueryStringParameters.Include); } @@ -39,7 +39,7 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr /// public virtual bool CanRead(string parameterName) { - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterName); return parameterName == "include"; } diff --git a/src/JsonApiDotNetCore/QueryStrings/LegacyFilterNotationConverter.cs b/src/JsonApiDotNetCore/QueryStrings/LegacyFilterNotationConverter.cs index 0480158133..eff147e3d4 100644 --- a/src/JsonApiDotNetCore/QueryStrings/LegacyFilterNotationConverter.cs +++ b/src/JsonApiDotNetCore/QueryStrings/LegacyFilterNotationConverter.cs @@ -22,7 +22,7 @@ public sealed class LegacyFilterNotationConverter public IEnumerable ExtractConditions(string parameterValue) { - ArgumentGuard.NotNullNorEmpty(parameterValue); + ArgumentException.ThrowIfNullOrEmpty(parameterValue); if (parameterValue.StartsWith(ParameterValuePrefix.Expression, StringComparison.Ordinal) || parameterValue.StartsWith(ParameterValuePrefix.In, StringComparison.Ordinal) || @@ -41,8 +41,8 @@ public IEnumerable ExtractConditions(string parameterValue) public (string parameterName, string parameterValue) Convert(string parameterName, string parameterValue) { - ArgumentGuard.NotNullNorEmpty(parameterName); - ArgumentGuard.NotNullNorEmpty(parameterValue); + ArgumentException.ThrowIfNullOrEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterValue); if (parameterValue.StartsWith(ParameterValuePrefix.Expression, StringComparison.Ordinal)) { diff --git a/src/JsonApiDotNetCore/QueryStrings/PaginationQueryStringParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/PaginationQueryStringParameterReader.cs index 6484253574..353204eee2 100644 --- a/src/JsonApiDotNetCore/QueryStrings/PaginationQueryStringParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/PaginationQueryStringParameterReader.cs @@ -31,8 +31,8 @@ public PaginationQueryStringParameterReader(IPaginationParser paginationParser, IJsonApiOptions options) : base(request, resourceGraph) { - ArgumentGuard.NotNull(paginationParser); - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(paginationParser); + ArgumentNullException.ThrowIfNull(options); _options = options; _paginationParser = paginationParser; @@ -41,7 +41,7 @@ public PaginationQueryStringParameterReader(IPaginationParser paginationParser, /// public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute) { - ArgumentGuard.NotNull(disableQueryStringAttribute); + ArgumentNullException.ThrowIfNull(disableQueryStringAttribute); return !IsAtomicOperationsRequest && !disableQueryStringAttribute.ContainsParameter(JsonApiQueryStringParameters.Page); } @@ -49,7 +49,7 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr /// public virtual bool CanRead(string parameterName) { - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterName); return parameterName is PageSizeParameterName or PageNumberParameterName; } @@ -95,7 +95,7 @@ private PaginationQueryStringValueExpression GetPageConstraint(string parameterV protected virtual void ValidatePageSize(PaginationQueryStringValueExpression constraint) { - ArgumentGuard.NotNull(constraint); + ArgumentNullException.ThrowIfNull(constraint); foreach (PaginationElementQueryStringValueExpression element in constraint.Elements) { @@ -121,7 +121,7 @@ protected virtual void ValidatePageSize(PaginationQueryStringValueExpression con protected virtual void ValidatePageNumber(PaginationQueryStringValueExpression constraint) { - ArgumentGuard.NotNull(constraint); + ArgumentNullException.ThrowIfNull(constraint); foreach (PaginationElementQueryStringValueExpression element in constraint.Elements) { diff --git a/src/JsonApiDotNetCore/QueryStrings/QueryStringParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/QueryStringParameterReader.cs index d3f5277881..1b59eed083 100644 --- a/src/JsonApiDotNetCore/QueryStrings/QueryStringParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/QueryStringParameterReader.cs @@ -16,8 +16,8 @@ public abstract class QueryStringParameterReader protected QueryStringParameterReader(IJsonApiRequest request, IResourceGraph resourceGraph) { - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(resourceGraph); _resourceGraph = resourceGraph; _isCollectionRequest = request.IsCollection; diff --git a/src/JsonApiDotNetCore/QueryStrings/QueryStringReader.cs b/src/JsonApiDotNetCore/QueryStrings/QueryStringReader.cs index fd19e78236..89337708e7 100644 --- a/src/JsonApiDotNetCore/QueryStrings/QueryStringReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/QueryStringReader.cs @@ -18,10 +18,10 @@ public sealed partial class QueryStringReader : IQueryStringReader public QueryStringReader(IJsonApiOptions options, IRequestQueryStringAccessor queryStringAccessor, IEnumerable parameterReaders, ILoggerFactory loggerFactory) { - ArgumentGuard.NotNull(loggerFactory); - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(queryStringAccessor); - ArgumentGuard.NotNull(parameterReaders); + ArgumentNullException.ThrowIfNull(loggerFactory); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(queryStringAccessor); + ArgumentNullException.ThrowIfNull(parameterReaders); _options = options; _queryStringAccessor = queryStringAccessor; diff --git a/src/JsonApiDotNetCore/QueryStrings/RequestQueryStringAccessor.cs b/src/JsonApiDotNetCore/QueryStrings/RequestQueryStringAccessor.cs index 00c0bfb69f..92b9a0a60a 100644 --- a/src/JsonApiDotNetCore/QueryStrings/RequestQueryStringAccessor.cs +++ b/src/JsonApiDotNetCore/QueryStrings/RequestQueryStringAccessor.cs @@ -22,7 +22,7 @@ public IQueryCollection Query public RequestQueryStringAccessor(IHttpContextAccessor httpContextAccessor) { - ArgumentGuard.NotNull(httpContextAccessor); + ArgumentNullException.ThrowIfNull(httpContextAccessor); _httpContextAccessor = httpContextAccessor; } diff --git a/src/JsonApiDotNetCore/QueryStrings/ResourceDefinitionQueryableParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/ResourceDefinitionQueryableParameterReader.cs index 54ed090d78..fb52e5775d 100644 --- a/src/JsonApiDotNetCore/QueryStrings/ResourceDefinitionQueryableParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/ResourceDefinitionQueryableParameterReader.cs @@ -21,8 +21,8 @@ public class ResourceDefinitionQueryableParameterReader : IResourceDefinitionQue public ResourceDefinitionQueryableParameterReader(IJsonApiRequest request, IResourceDefinitionAccessor resourceDefinitionAccessor) { - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(resourceDefinitionAccessor); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor); _request = request; _resourceDefinitionAccessor = resourceDefinitionAccessor; @@ -37,7 +37,7 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr /// public virtual bool CanRead(string parameterName) { - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterName); if (_request.Kind == EndpointKind.AtomicOperations) { diff --git a/src/JsonApiDotNetCore/QueryStrings/SortQueryStringParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/SortQueryStringParameterReader.cs index 98d11b2344..203ee70235 100644 --- a/src/JsonApiDotNetCore/QueryStrings/SortQueryStringParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/SortQueryStringParameterReader.cs @@ -25,8 +25,8 @@ public SortQueryStringParameterReader(IQueryStringParameterScopeParser scopePars IResourceGraph resourceGraph) : base(request, resourceGraph) { - ArgumentGuard.NotNull(scopeParser); - ArgumentGuard.NotNull(sortParser); + ArgumentNullException.ThrowIfNull(scopeParser); + ArgumentNullException.ThrowIfNull(sortParser); _scopeParser = scopeParser; _sortParser = sortParser; @@ -35,7 +35,7 @@ public SortQueryStringParameterReader(IQueryStringParameterScopeParser scopePars /// public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute) { - ArgumentGuard.NotNull(disableQueryStringAttribute); + ArgumentNullException.ThrowIfNull(disableQueryStringAttribute); return !IsAtomicOperationsRequest && !disableQueryStringAttribute.ContainsParameter(JsonApiQueryStringParameters.Sort); } @@ -43,7 +43,7 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr /// public virtual bool CanRead(string parameterName) { - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterName); bool isNested = parameterName.StartsWith("sort[", StringComparison.Ordinal) && parameterName.EndsWith(']'); return parameterName == "sort" || isNested; diff --git a/src/JsonApiDotNetCore/QueryStrings/SparseFieldSetQueryStringParameterReader.cs b/src/JsonApiDotNetCore/QueryStrings/SparseFieldSetQueryStringParameterReader.cs index ad2d728fa8..308fe44588 100644 --- a/src/JsonApiDotNetCore/QueryStrings/SparseFieldSetQueryStringParameterReader.cs +++ b/src/JsonApiDotNetCore/QueryStrings/SparseFieldSetQueryStringParameterReader.cs @@ -30,8 +30,8 @@ public SparseFieldSetQueryStringParameterReader(ISparseFieldTypeParser scopePars IResourceGraph resourceGraph) : base(request, resourceGraph) { - ArgumentGuard.NotNull(scopeParser); - ArgumentGuard.NotNull(sparseFieldSetParser); + ArgumentNullException.ThrowIfNull(scopeParser); + ArgumentNullException.ThrowIfNull(sparseFieldSetParser); _scopeParser = scopeParser; _sparseFieldSetParser = sparseFieldSetParser; @@ -40,7 +40,7 @@ public SparseFieldSetQueryStringParameterReader(ISparseFieldTypeParser scopePars /// public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute) { - ArgumentGuard.NotNull(disableQueryStringAttribute); + ArgumentNullException.ThrowIfNull(disableQueryStringAttribute); return !IsAtomicOperationsRequest && !disableQueryStringAttribute.ContainsParameter(JsonApiQueryStringParameters.Fields); } @@ -48,7 +48,7 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr /// public virtual bool CanRead(string parameterName) { - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentException.ThrowIfNullOrEmpty(parameterName); return parameterName.StartsWith("fields[", StringComparison.Ordinal) && parameterName.EndsWith(']'); } diff --git a/src/JsonApiDotNetCore/Repositories/DbContextExtensions.cs b/src/JsonApiDotNetCore/Repositories/DbContextExtensions.cs index f78841defc..0e7089acec 100644 --- a/src/JsonApiDotNetCore/Repositories/DbContextExtensions.cs +++ b/src/JsonApiDotNetCore/Repositories/DbContextExtensions.cs @@ -13,8 +13,8 @@ public static class DbContextExtensions /// public static IIdentifiable GetTrackedOrAttach(this DbContext dbContext, IIdentifiable resource) { - ArgumentGuard.NotNull(dbContext); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(dbContext); + ArgumentNullException.ThrowIfNull(resource); var trackedIdentifiable = (IIdentifiable?)dbContext.GetTrackedIdentifiable(resource); @@ -32,8 +32,8 @@ public static IIdentifiable GetTrackedOrAttach(this DbContext dbContext, IIdenti /// public static object? GetTrackedIdentifiable(this DbContext dbContext, IIdentifiable identifiable) { - ArgumentGuard.NotNull(dbContext); - ArgumentGuard.NotNull(identifiable); + ArgumentNullException.ThrowIfNull(dbContext); + ArgumentNullException.ThrowIfNull(identifiable); Type resourceClrType = identifiable.GetClrType(); string? stringId = identifiable.StringId; @@ -53,7 +53,7 @@ private static bool IsResource(EntityEntry entry, Type resourceClrType, string? /// public static void ResetChangeTracker(this DbContext dbContext) { - ArgumentGuard.NotNull(dbContext); + ArgumentNullException.ThrowIfNull(dbContext); dbContext.ChangeTracker.Clear(); } diff --git a/src/JsonApiDotNetCore/Repositories/DbContextResolver.cs b/src/JsonApiDotNetCore/Repositories/DbContextResolver.cs index bc275a96c1..c48169df72 100644 --- a/src/JsonApiDotNetCore/Repositories/DbContextResolver.cs +++ b/src/JsonApiDotNetCore/Repositories/DbContextResolver.cs @@ -15,7 +15,7 @@ public sealed class DbContextResolver : IDbContextResolver public DbContextResolver(TDbContext dbContext) { - ArgumentGuard.NotNull(dbContext); + ArgumentNullException.ThrowIfNull(dbContext); _dbContext = dbContext; } diff --git a/src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs b/src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs index 0dc43487da..214987828a 100644 --- a/src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs +++ b/src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs @@ -46,13 +46,13 @@ public EntityFrameworkCoreRepository(ITargetedFields targetedFields, IDbContextR IResourceFactory resourceFactory, IEnumerable constraintProviders, ILoggerFactory loggerFactory, IResourceDefinitionAccessor resourceDefinitionAccessor) { - ArgumentGuard.NotNull(targetedFields); - ArgumentGuard.NotNull(dbContextResolver); - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(resourceFactory); - ArgumentGuard.NotNull(constraintProviders); - ArgumentGuard.NotNull(loggerFactory); - ArgumentGuard.NotNull(resourceDefinitionAccessor); + ArgumentNullException.ThrowIfNull(targetedFields); + ArgumentNullException.ThrowIfNull(dbContextResolver); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(resourceFactory); + ArgumentNullException.ThrowIfNull(constraintProviders); + ArgumentNullException.ThrowIfNull(loggerFactory); + ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor); _targetedFields = targetedFields; _dbContext = dbContextResolver.GetContext(); @@ -71,7 +71,7 @@ public virtual async Task> GetAsync(QueryLayer qu queryLayer }); - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(queryLayer); using (CodeTimingSessionManager.Current.Measure("Repository - Get resource(s)")) { @@ -113,14 +113,14 @@ public virtual async Task CountAsync(FilterExpression? filter, Cancellation protected virtual IQueryable ApplyQueryLayer(QueryLayer queryLayer) { - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(queryLayer); _traceWriter.LogMethodStart(new { queryLayer }); - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(queryLayer); using (CodeTimingSessionManager.Current.Measure("Convert QueryLayer to System.Expression")) { @@ -189,7 +189,7 @@ public virtual Task GetForCreateAsync(Type resourceClrType, [Disallow id }); - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); var resource = (TResource)_resourceFactory.CreateInstance(resourceClrType); resource.Id = id; @@ -206,8 +206,8 @@ public virtual async Task CreateAsync(TResource resourceFromRequest, TResource r resourceForDatabase }); - ArgumentGuard.NotNull(resourceFromRequest); - ArgumentGuard.NotNull(resourceForDatabase); + ArgumentNullException.ThrowIfNull(resourceFromRequest); + ArgumentNullException.ThrowIfNull(resourceForDatabase); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Create resource"); @@ -268,7 +268,7 @@ await _resourceDefinitionAccessor.OnSetToManyRelationshipAsync(leftResource, has queryLayer }); - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(queryLayer); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Get resource for update"); @@ -285,8 +285,8 @@ public virtual async Task UpdateAsync(TResource resourceFromRequest, TResource r resourceFromDatabase }); - ArgumentGuard.NotNull(resourceFromRequest); - ArgumentGuard.NotNull(resourceFromDatabase); + ArgumentNullException.ThrowIfNull(resourceFromRequest); + ArgumentNullException.ThrowIfNull(resourceFromDatabase); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Update resource"); @@ -318,7 +318,7 @@ public virtual async Task UpdateAsync(TResource resourceFromRequest, TResource r protected void AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute relationship, object? rightValue) { - ArgumentGuard.NotNull(relationship); + ArgumentNullException.ThrowIfNull(relationship); if (relationship is HasOneAttribute) { @@ -415,7 +415,7 @@ public virtual async Task SetRelationshipAsync(TResource leftResource, object? r rightValue }); - ArgumentGuard.NotNull(leftResource); + ArgumentNullException.ThrowIfNull(leftResource); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Set relationship"); @@ -446,7 +446,7 @@ public virtual async Task AddToToManyRelationshipAsync(TResource? leftResource, rightResourceIds }); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(rightResourceIds); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Add to to-many relationship"); @@ -510,8 +510,8 @@ public virtual async Task RemoveFromToManyRelationshipAsync(TResource leftResour rightResourceIds }); - ArgumentGuard.NotNull(leftResource); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(leftResource); + ArgumentNullException.ThrowIfNull(rightResourceIds); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Remove from to-many relationship"); @@ -600,8 +600,8 @@ private void MarkManyToManyRelationshipAsLoaded(EntityEntry leftEntry protected async Task UpdateRelationshipAsync(RelationshipAttribute relationship, TResource leftResource, object? valueToAssign, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(leftResource); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(leftResource); object? trackedValueToAssign = EnsureRelationshipValueToAssignIsTracked(valueToAssign, relationship.Property.PropertyType); diff --git a/src/JsonApiDotNetCore/Repositories/ResourceRepositoryAccessor.cs b/src/JsonApiDotNetCore/Repositories/ResourceRepositoryAccessor.cs index 827c2259fd..cf85eaa40b 100644 --- a/src/JsonApiDotNetCore/Repositories/ResourceRepositoryAccessor.cs +++ b/src/JsonApiDotNetCore/Repositories/ResourceRepositoryAccessor.cs @@ -20,9 +20,9 @@ public class ResourceRepositoryAccessor : IResourceRepositoryAccessor public ResourceRepositoryAccessor(IServiceProvider serviceProvider, IResourceGraph resourceGraph, IJsonApiRequest request) { - ArgumentGuard.NotNull(serviceProvider); - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(request); + ArgumentNullException.ThrowIfNull(serviceProvider); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(request); _serviceProvider = serviceProvider; _resourceGraph = resourceGraph; @@ -41,7 +41,7 @@ public ResourceType LookupResourceType(Type resourceClrType) public async Task> GetAsync(QueryLayer queryLayer, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(queryLayer); dynamic repository = ResolveReadRepository(typeof(TResource)); return (IReadOnlyCollection)await repository.GetAsync(queryLayer, cancellationToken); @@ -50,8 +50,8 @@ public async Task> GetAsync(QueryLayer /// public async Task> GetAsync(ResourceType resourceType, QueryLayer queryLayer, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(queryLayer); dynamic repository = ResolveReadRepository(resourceType); return (IReadOnlyCollection)await repository.GetAsync(queryLayer, cancellationToken); @@ -60,7 +60,7 @@ public async Task> GetAsync(ResourceType reso /// public async Task CountAsync(ResourceType resourceType, FilterExpression? filter, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic repository = ResolveReadRepository(resourceType); return (int)await repository.CountAsync(filter, cancellationToken); @@ -70,7 +70,7 @@ public async Task CountAsync(ResourceType resourceType, FilterExpression? f public async Task GetForCreateAsync(Type resourceClrType, [DisallowNull] TId id, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); dynamic repository = GetWriteRepository(typeof(TResource)); return await repository.GetForCreateAsync(resourceClrType, id, cancellationToken); @@ -80,8 +80,8 @@ public async Task GetForCreateAsync(Type resourceClrT public async Task CreateAsync(TResource resourceFromRequest, TResource resourceForDatabase, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(resourceFromRequest); - ArgumentGuard.NotNull(resourceForDatabase); + ArgumentNullException.ThrowIfNull(resourceFromRequest); + ArgumentNullException.ThrowIfNull(resourceForDatabase); dynamic repository = GetWriteRepository(typeof(TResource)); await repository.CreateAsync(resourceFromRequest, resourceForDatabase, cancellationToken); @@ -91,7 +91,7 @@ public async Task CreateAsync(TResource resourceFromRequest, TResourc public async Task GetForUpdateAsync(QueryLayer queryLayer, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(queryLayer); + ArgumentNullException.ThrowIfNull(queryLayer); dynamic repository = GetWriteRepository(typeof(TResource)); return await repository.GetForUpdateAsync(queryLayer, cancellationToken); @@ -101,8 +101,8 @@ public async Task CreateAsync(TResource resourceFromRequest, TResourc public async Task UpdateAsync(TResource resourceFromRequest, TResource resourceFromDatabase, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(resourceFromRequest); - ArgumentGuard.NotNull(resourceFromDatabase); + ArgumentNullException.ThrowIfNull(resourceFromRequest); + ArgumentNullException.ThrowIfNull(resourceFromDatabase); dynamic repository = GetWriteRepository(typeof(TResource)); await repository.UpdateAsync(resourceFromRequest, resourceFromDatabase, cancellationToken); @@ -120,7 +120,7 @@ public async Task DeleteAsync(TResource? resourceFromDatabase, [ public async Task SetRelationshipAsync(TResource leftResource, object? rightValue, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(leftResource); + ArgumentNullException.ThrowIfNull(leftResource); dynamic repository = GetWriteRepository(typeof(TResource)); await repository.SetRelationshipAsync(leftResource, rightValue, cancellationToken); @@ -131,7 +131,7 @@ public async Task AddToToManyRelationshipAsync(TResource? leftRe CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(rightResourceIds); dynamic repository = GetWriteRepository(typeof(TResource)); await repository.AddToToManyRelationshipAsync(leftResource, leftId, rightResourceIds, cancellationToken); @@ -142,8 +142,8 @@ public async Task RemoveFromToManyRelationshipAsync(TResource leftRes CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(leftResource); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(leftResource); + ArgumentNullException.ThrowIfNull(rightResourceIds); dynamic repository = GetWriteRepository(typeof(TResource)); await repository.RemoveFromToManyRelationshipAsync(leftResource, rightResourceIds, cancellationToken); @@ -151,7 +151,7 @@ public async Task RemoveFromToManyRelationshipAsync(TResource leftRes protected object ResolveReadRepository(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); ResourceType resourceType = _resourceGraph.GetResourceType(resourceClrType); return ResolveReadRepository(resourceType); @@ -159,7 +159,7 @@ protected object ResolveReadRepository(Type resourceClrType) protected virtual object ResolveReadRepository(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Type repositoryType = typeof(IResourceReadRepository<,>).MakeGenericType(resourceType.ClrType, resourceType.IdentityClrType); return _serviceProvider.GetRequiredService(repositoryType); @@ -188,7 +188,7 @@ private object GetWriteRepository(Type resourceClrType) protected virtual object ResolveWriteRepository(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); ResourceType resourceType = _resourceGraph.GetResourceType(resourceClrType); diff --git a/src/JsonApiDotNetCore/Resources/AbstractResourceWrapper.cs b/src/JsonApiDotNetCore/Resources/AbstractResourceWrapper.cs index c3a193d3cd..3cf6233cf2 100644 --- a/src/JsonApiDotNetCore/Resources/AbstractResourceWrapper.cs +++ b/src/JsonApiDotNetCore/Resources/AbstractResourceWrapper.cs @@ -8,7 +8,7 @@ internal sealed class AbstractResourceWrapper : Identifiable, IAbstrac public AbstractResourceWrapper(Type abstractType) { - ArgumentGuard.NotNull(abstractType); + ArgumentNullException.ThrowIfNull(abstractType); AbstractType = abstractType; } diff --git a/src/JsonApiDotNetCore/Resources/IdentifiableExtensions.cs b/src/JsonApiDotNetCore/Resources/IdentifiableExtensions.cs index 91905e4df3..d4e3c156cb 100644 --- a/src/JsonApiDotNetCore/Resources/IdentifiableExtensions.cs +++ b/src/JsonApiDotNetCore/Resources/IdentifiableExtensions.cs @@ -8,7 +8,7 @@ internal static class IdentifiableExtensions public static object GetTypedId(this IIdentifiable identifiable) { - ArgumentGuard.NotNull(identifiable); + ArgumentNullException.ThrowIfNull(identifiable); PropertyInfo? property = identifiable.GetClrType().GetProperty(IdPropertyName); @@ -31,7 +31,7 @@ public static object GetTypedId(this IIdentifiable identifiable) public static Type GetClrType(this IIdentifiable identifiable) { - ArgumentGuard.NotNull(identifiable); + ArgumentNullException.ThrowIfNull(identifiable); return identifiable is IAbstractResourceWrapper abstractResource ? abstractResource.AbstractType : identifiable.GetType(); } diff --git a/src/JsonApiDotNetCore/Resources/JsonApiResourceDefinition.cs b/src/JsonApiDotNetCore/Resources/JsonApiResourceDefinition.cs index f069c155e8..e2a354ca76 100644 --- a/src/JsonApiDotNetCore/Resources/JsonApiResourceDefinition.cs +++ b/src/JsonApiDotNetCore/Resources/JsonApiResourceDefinition.cs @@ -26,7 +26,7 @@ public class JsonApiResourceDefinition : IResourceDefinition(); diff --git a/src/JsonApiDotNetCore/Resources/OperationContainer.cs b/src/JsonApiDotNetCore/Resources/OperationContainer.cs index 2c8ec00d17..dd2cfe2630 100644 --- a/src/JsonApiDotNetCore/Resources/OperationContainer.cs +++ b/src/JsonApiDotNetCore/Resources/OperationContainer.cs @@ -16,9 +16,9 @@ public sealed class OperationContainer public OperationContainer(IIdentifiable resource, ITargetedFields targetedFields, IJsonApiRequest request) { - ArgumentGuard.NotNull(resource); - ArgumentGuard.NotNull(targetedFields); - ArgumentGuard.NotNull(request); + ArgumentNullException.ThrowIfNull(resource); + ArgumentNullException.ThrowIfNull(targetedFields); + ArgumentNullException.ThrowIfNull(request); Resource = resource; TargetedFields = targetedFields; @@ -32,7 +32,7 @@ public void SetTransactionId(string transactionId) public OperationContainer WithResource(IIdentifiable resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); return new OperationContainer(resource, TargetedFields, Request); } diff --git a/src/JsonApiDotNetCore/Resources/ResourceChangeTracker.cs b/src/JsonApiDotNetCore/Resources/ResourceChangeTracker.cs index 795c33f16b..c17ce60b45 100644 --- a/src/JsonApiDotNetCore/Resources/ResourceChangeTracker.cs +++ b/src/JsonApiDotNetCore/Resources/ResourceChangeTracker.cs @@ -18,8 +18,8 @@ public sealed class ResourceChangeTracker : IResourceChangeTracker public void SetInitiallyStoredAttributeValues(TResource resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); _initiallyStoredAttributeValues = CreateAttributeDictionary(resource, _request.PrimaryResourceType!.Attributes); } @@ -36,7 +36,7 @@ public void SetInitiallyStoredAttributeValues(TResource resource) /// public void SetRequestAttributeValues(TResource resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); _requestAttributeValues = CreateAttributeDictionary(resource, _targetedFields.Attributes); } @@ -44,7 +44,7 @@ public void SetRequestAttributeValues(TResource resource) /// public void SetFinallyStoredAttributeValues(TResource resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); _finallyStoredAttributeValues = CreateAttributeDictionary(resource, _request.PrimaryResourceType!.Attributes); } diff --git a/src/JsonApiDotNetCore/Resources/ResourceDefinitionAccessor.cs b/src/JsonApiDotNetCore/Resources/ResourceDefinitionAccessor.cs index 28079b7e2a..a225766fb5 100644 --- a/src/JsonApiDotNetCore/Resources/ResourceDefinitionAccessor.cs +++ b/src/JsonApiDotNetCore/Resources/ResourceDefinitionAccessor.cs @@ -33,8 +33,8 @@ public bool IsReadOnlyRequest public ResourceDefinitionAccessor(IResourceGraph resourceGraph, IServiceProvider serviceProvider) { - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(serviceProvider); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(serviceProvider); _resourceGraph = resourceGraph; _serviceProvider = serviceProvider; @@ -43,7 +43,7 @@ public ResourceDefinitionAccessor(IResourceGraph resourceGraph, IServiceProvider /// public IImmutableSet OnApplyIncludes(ResourceType resourceType, IImmutableSet existingIncludes) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic resourceDefinition = ResolveResourceDefinition(resourceType); return resourceDefinition.OnApplyIncludes(existingIncludes); @@ -52,7 +52,7 @@ public IImmutableSet OnApplyIncludes(ResourceType reso /// public FilterExpression? OnApplyFilter(ResourceType resourceType, FilterExpression? existingFilter) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic resourceDefinition = ResolveResourceDefinition(resourceType); return resourceDefinition.OnApplyFilter(existingFilter); @@ -61,7 +61,7 @@ public IImmutableSet OnApplyIncludes(ResourceType reso /// public SortExpression? OnApplySort(ResourceType resourceType, SortExpression? existingSort) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic resourceDefinition = ResolveResourceDefinition(resourceType); return resourceDefinition.OnApplySort(existingSort); @@ -70,7 +70,7 @@ public IImmutableSet OnApplyIncludes(ResourceType reso /// public PaginationExpression? OnApplyPagination(ResourceType resourceType, PaginationExpression? existingPagination) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic resourceDefinition = ResolveResourceDefinition(resourceType); return resourceDefinition.OnApplyPagination(existingPagination); @@ -79,7 +79,7 @@ public IImmutableSet OnApplyIncludes(ResourceType reso /// public SparseFieldSetExpression? OnApplySparseFieldSet(ResourceType resourceType, SparseFieldSetExpression? existingSparseFieldSet) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic resourceDefinition = ResolveResourceDefinition(resourceType); return resourceDefinition.OnApplySparseFieldSet(existingSparseFieldSet); @@ -88,8 +88,8 @@ public IImmutableSet OnApplyIncludes(ResourceType reso /// public object? GetQueryableHandlerForQueryStringParameter(Type resourceClrType, string parameterName) { - ArgumentGuard.NotNull(resourceClrType); - ArgumentGuard.NotNullNorEmpty(parameterName); + ArgumentNullException.ThrowIfNull(resourceClrType); + ArgumentException.ThrowIfNullOrEmpty(parameterName); dynamic resourceDefinition = ResolveResourceDefinition(resourceClrType); dynamic? handlers = resourceDefinition.OnRegisterQueryableHandlersForQueryStringParameters(); @@ -108,7 +108,7 @@ public IImmutableSet OnApplyIncludes(ResourceType reso /// public IDictionary? GetMeta(ResourceType resourceType, IIdentifiable resourceInstance) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); dynamic resourceDefinition = ResolveResourceDefinition(resourceType); return resourceDefinition.GetMeta((dynamic)resourceInstance); @@ -118,7 +118,7 @@ public IImmutableSet OnApplyIncludes(ResourceType reso public async Task OnPrepareWriteAsync(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); dynamic resourceDefinition = ResolveResourceDefinition(resource.GetClrType()); await resourceDefinition.OnPrepareWriteAsync((dynamic)resource, writeOperation, cancellationToken); @@ -129,8 +129,8 @@ public async Task OnPrepareWriteAsync(TResource resource, WriteOperat IIdentifiable? rightResourceId, WriteOperationKind writeOperation, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(leftResource); - ArgumentGuard.NotNull(hasOneRelationship); + ArgumentNullException.ThrowIfNull(leftResource); + ArgumentNullException.ThrowIfNull(hasOneRelationship); dynamic resourceDefinition = ResolveResourceDefinition(leftResource.GetClrType()); @@ -143,9 +143,9 @@ public async Task OnSetToManyRelationshipAsync(TResource leftResource ISet rightResourceIds, WriteOperationKind writeOperation, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(leftResource); - ArgumentGuard.NotNull(hasManyRelationship); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(leftResource); + ArgumentNullException.ThrowIfNull(hasManyRelationship); + ArgumentNullException.ThrowIfNull(rightResourceIds); dynamic resourceDefinition = ResolveResourceDefinition(leftResource.GetClrType()); await resourceDefinition.OnSetToManyRelationshipAsync((dynamic)leftResource, hasManyRelationship, rightResourceIds, writeOperation, cancellationToken); @@ -156,8 +156,8 @@ public async Task OnAddToRelationshipAsync(TResource leftResource, Ha CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(hasManyRelationship); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(hasManyRelationship); + ArgumentNullException.ThrowIfNull(rightResourceIds); dynamic resourceDefinition = ResolveResourceDefinition(leftResource.GetClrType()); await resourceDefinition.OnAddToRelationshipAsync((dynamic)leftResource, hasManyRelationship, rightResourceIds, cancellationToken); @@ -168,9 +168,9 @@ public async Task OnRemoveFromRelationshipAsync(TResource leftResourc ISet rightResourceIds, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(leftResource); - ArgumentGuard.NotNull(hasManyRelationship); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(leftResource); + ArgumentNullException.ThrowIfNull(hasManyRelationship); + ArgumentNullException.ThrowIfNull(rightResourceIds); dynamic resourceDefinition = ResolveResourceDefinition(leftResource.GetClrType()); await resourceDefinition.OnRemoveFromRelationshipAsync((dynamic)leftResource, hasManyRelationship, rightResourceIds, cancellationToken); @@ -180,7 +180,7 @@ public async Task OnRemoveFromRelationshipAsync(TResource leftResourc public async Task OnWritingAsync(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); dynamic resourceDefinition = ResolveResourceDefinition(resource.GetClrType()); await resourceDefinition.OnWritingAsync((dynamic)resource, writeOperation, cancellationToken); @@ -190,7 +190,7 @@ public async Task OnWritingAsync(TResource resource, WriteOperationKi public async Task OnWriteSucceededAsync(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken) where TResource : class, IIdentifiable { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); dynamic resourceDefinition = ResolveResourceDefinition(resource.GetClrType()); await resourceDefinition.OnWriteSucceededAsync((dynamic)resource, writeOperation, cancellationToken); @@ -199,7 +199,7 @@ public async Task OnWriteSucceededAsync(TResource resource, WriteOper /// public void OnDeserialize(IIdentifiable resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); dynamic resourceDefinition = ResolveResourceDefinition(resource.GetClrType()); resourceDefinition.OnDeserialize((dynamic)resource); @@ -208,7 +208,7 @@ public void OnDeserialize(IIdentifiable resource) /// public void OnSerialize(IIdentifiable resource) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); dynamic resourceDefinition = ResolveResourceDefinition(resource.GetClrType()); resourceDefinition.OnSerialize((dynamic)resource); @@ -216,7 +216,7 @@ public void OnSerialize(IIdentifiable resource) protected object ResolveResourceDefinition(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); ResourceType resourceType = _resourceGraph.GetResourceType(resourceClrType); return ResolveResourceDefinition(resourceType); @@ -224,7 +224,7 @@ protected object ResolveResourceDefinition(Type resourceClrType) protected virtual object ResolveResourceDefinition(ResourceType resourceType) { - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resourceType); Type resourceDefinitionType = typeof(IResourceDefinition<,>).MakeGenericType(resourceType.ClrType, resourceType.IdentityClrType); return _serviceProvider.GetRequiredService(resourceDefinitionType); diff --git a/src/JsonApiDotNetCore/Resources/ResourceFactory.cs b/src/JsonApiDotNetCore/Resources/ResourceFactory.cs index 9b02953c84..5a18763939 100644 --- a/src/JsonApiDotNetCore/Resources/ResourceFactory.cs +++ b/src/JsonApiDotNetCore/Resources/ResourceFactory.cs @@ -15,7 +15,7 @@ internal sealed class ResourceFactory : IResourceFactory public ResourceFactory(IServiceProvider serviceProvider) { - ArgumentGuard.NotNull(serviceProvider); + ArgumentNullException.ThrowIfNull(serviceProvider); _serviceProvider = serviceProvider; } @@ -23,7 +23,7 @@ public ResourceFactory(IServiceProvider serviceProvider) /// public IIdentifiable CreateInstance(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); if (!resourceClrType.IsAssignableTo(typeof(IIdentifiable))) { @@ -85,7 +85,7 @@ private static IIdentifiable InnerCreateInstance(Type type, IServiceProvider ser /// public NewExpression CreateNewExpression(Type resourceClrType) { - ArgumentGuard.NotNull(resourceClrType); + ArgumentNullException.ThrowIfNull(resourceClrType); if (HasSingleConstructorWithoutParameters(resourceClrType)) { diff --git a/src/JsonApiDotNetCore/Resources/SortExpressionLambdaConverter.cs b/src/JsonApiDotNetCore/Resources/SortExpressionLambdaConverter.cs index 92862d4d99..97e014f344 100644 --- a/src/JsonApiDotNetCore/Resources/SortExpressionLambdaConverter.cs +++ b/src/JsonApiDotNetCore/Resources/SortExpressionLambdaConverter.cs @@ -15,14 +15,14 @@ internal sealed class SortExpressionLambdaConverter public SortExpressionLambdaConverter(IResourceGraph resourceGraph) { - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(resourceGraph); _resourceGraph = resourceGraph; } public SortElementExpression FromLambda(Expression> keySelector, ListSortDirection sortDirection) { - ArgumentGuard.NotNull(keySelector); + ArgumentNullException.ThrowIfNull(keySelector); _fields.Clear(); diff --git a/src/JsonApiDotNetCore/Resources/TargetedFields.cs b/src/JsonApiDotNetCore/Resources/TargetedFields.cs index 3b44c4a261..420058106f 100644 --- a/src/JsonApiDotNetCore/Resources/TargetedFields.cs +++ b/src/JsonApiDotNetCore/Resources/TargetedFields.cs @@ -16,7 +16,7 @@ public sealed class TargetedFields : ITargetedFields /// public void CopyFrom(ITargetedFields other) { - ArgumentGuard.NotNull(other); + ArgumentNullException.ThrowIfNull(other); Clear(); diff --git a/src/JsonApiDotNetCore/Serialization/JsonConverters/JsonObjectConverter.cs b/src/JsonApiDotNetCore/Serialization/JsonConverters/JsonObjectConverter.cs index c470b991d6..054fc28e55 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonConverters/JsonObjectConverter.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonConverters/JsonObjectConverter.cs @@ -7,7 +7,7 @@ public abstract class JsonObjectConverter : JsonConverter { protected static TValue? ReadSubTree(ref Utf8JsonReader reader, JsonSerializerOptions options) { - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(options); if (typeof(TValue) != typeof(object) && options.GetConverter(typeof(TValue)) is JsonConverter converter) { @@ -19,7 +19,7 @@ public abstract class JsonObjectConverter : JsonConverter protected static void WriteSubTree(Utf8JsonWriter writer, TValue value, JsonSerializerOptions options) { - ArgumentGuard.NotNull(options); + ArgumentNullException.ThrowIfNull(options); if (typeof(TValue) != typeof(object) && options.GetConverter(typeof(TValue)) is JsonConverter converter) { diff --git a/src/JsonApiDotNetCore/Serialization/JsonConverters/ResourceObjectConverter.cs b/src/JsonApiDotNetCore/Serialization/JsonConverters/ResourceObjectConverter.cs index fcb950b39b..369adee7a3 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonConverters/ResourceObjectConverter.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonConverters/ResourceObjectConverter.cs @@ -27,7 +27,7 @@ public class ResourceObjectConverter : JsonObjectConverter public ResourceObjectConverter(IResourceGraph resourceGraph) { - ArgumentGuard.NotNull(resourceGraph); + ArgumentNullException.ThrowIfNull(resourceGraph); _resourceGraph = resourceGraph; } @@ -287,8 +287,8 @@ private protected virtual void ValidateExtensionInRelationships(string extension /// public override void Write(Utf8JsonWriter writer, ResourceObject value, JsonSerializerOptions options) { - ArgumentGuard.NotNull(writer); - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(writer); + ArgumentNullException.ThrowIfNull(value); writer.WriteStartObject(); diff --git a/src/JsonApiDotNetCore/Serialization/JsonConverters/SingleOrManyDataConverterFactory.cs b/src/JsonApiDotNetCore/Serialization/JsonConverters/SingleOrManyDataConverterFactory.cs index 48d90f9c8f..81ae41a380 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonConverters/SingleOrManyDataConverterFactory.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonConverters/SingleOrManyDataConverterFactory.cs @@ -14,7 +14,7 @@ public sealed class SingleOrManyDataConverterFactory : JsonConverterFactory /// public override bool CanConvert(Type typeToConvert) { - ArgumentGuard.NotNull(typeToConvert); + ArgumentNullException.ThrowIfNull(typeToConvert); return typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(SingleOrManyData<>); } @@ -22,7 +22,7 @@ public override bool CanConvert(Type typeToConvert) /// public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { - ArgumentGuard.NotNull(typeToConvert); + ArgumentNullException.ThrowIfNull(typeToConvert); Type objectType = typeToConvert.GetGenericArguments()[0]; Type converterType = typeof(SingleOrManyDataConverter<>).MakeGenericType(objectType); diff --git a/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyDocumentConverter.cs b/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyDocumentConverter.cs index 2195ff2ec8..f459b49c9b 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyDocumentConverter.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyDocumentConverter.cs @@ -32,8 +32,8 @@ public override Document Read(ref Utf8JsonReader reader, Type typeToConvert, Jso /// public override void Write(Utf8JsonWriter writer, Document value, JsonSerializerOptions options) { - ArgumentGuard.NotNull(writer); - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(writer); + ArgumentNullException.ThrowIfNull(value); writer.WriteStartObject(); diff --git a/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyRelationshipObjectConverter.cs b/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyRelationshipObjectConverter.cs index 30a26c055b..db6b7dc686 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyRelationshipObjectConverter.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonConverters/WriteOnlyRelationshipObjectConverter.cs @@ -27,8 +27,8 @@ public override RelationshipObject Read(ref Utf8JsonReader reader, Type typeToCo /// public override void Write(Utf8JsonWriter writer, RelationshipObject value, JsonSerializerOptions options) { - ArgumentGuard.NotNull(writer); - ArgumentGuard.NotNull(value); + ArgumentNullException.ThrowIfNull(writer); + ArgumentNullException.ThrowIfNull(value); writer.WriteStartObject(); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicOperationObjectAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicOperationObjectAdapter.cs index a9205ce4fa..4339cf6c48 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicOperationObjectAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicOperationObjectAdapter.cs @@ -17,10 +17,10 @@ public sealed class AtomicOperationObjectAdapter : IAtomicOperationObjectAdapter public AtomicOperationObjectAdapter(IJsonApiOptions options, IAtomicReferenceAdapter atomicReferenceAdapter, IResourceDataInOperationsRequestAdapter resourceDataInOperationsRequestAdapter, IRelationshipDataAdapter relationshipDataAdapter) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(atomicReferenceAdapter); - ArgumentGuard.NotNull(resourceDataInOperationsRequestAdapter); - ArgumentGuard.NotNull(relationshipDataAdapter); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(atomicReferenceAdapter); + ArgumentNullException.ThrowIfNull(resourceDataInOperationsRequestAdapter); + ArgumentNullException.ThrowIfNull(relationshipDataAdapter); _options = options; _atomicReferenceAdapter = atomicReferenceAdapter; @@ -31,8 +31,8 @@ public AtomicOperationObjectAdapter(IJsonApiOptions options, IAtomicReferenceAda /// public OperationContainer Convert(AtomicOperationObject atomicOperationObject, RequestAdapterState state) { - ArgumentGuard.NotNull(atomicOperationObject); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(atomicOperationObject); + ArgumentNullException.ThrowIfNull(state); AssertNoHref(atomicOperationObject, state); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceAdapter.cs index 8e682439aa..0dc72a08fa 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceAdapter.cs @@ -14,9 +14,9 @@ public sealed class AtomicReferenceAdapter(IResourceGraph resourceGraph, IResour /// public AtomicReferenceResult Convert(AtomicReference atomicReference, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(atomicReference); - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(atomicReference); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); using IDisposable _ = state.Position.PushElement("ref"); (IIdentifiable resource, ResourceType resourceType) = ConvertResourceIdentity(atomicReference, requirements, state); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceResult.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceResult.cs index a15ecd8e0c..367d7ec2ea 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceResult.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/AtomicReferenceResult.cs @@ -17,8 +17,8 @@ public sealed class AtomicReferenceResult public AtomicReferenceResult(IIdentifiable resource, ResourceType resourceType, RelationshipAttribute? relationship) { - ArgumentGuard.NotNull(resource); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resource); + ArgumentNullException.ThrowIfNull(resourceType); Resource = resource; ResourceType = resourceType; diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/BaseAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/BaseAdapter.cs index f7bbcb2121..8969d28fd7 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/BaseAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/BaseAdapter.cs @@ -13,7 +13,7 @@ public abstract class BaseAdapter protected static void AssertHasData(SingleOrManyData data, RequestAdapterState state) where T : ResourceIdentifierObject, new() { - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(state); if (!data.IsAssigned) { @@ -25,7 +25,7 @@ protected static void AssertHasData(SingleOrManyData data, RequestAdapterS protected static void AssertDataHasSingleValue(SingleOrManyData data, bool allowNull, RequestAdapterState state) where T : ResourceIdentifierObject, new() { - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(state); if (data.SingleValue == null) { @@ -50,7 +50,7 @@ protected static void AssertDataHasSingleValue(SingleOrManyData data, bool protected static void AssertDataHasManyValue(SingleOrManyData data, RequestAdapterState state) where T : ResourceIdentifierObject, new() { - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(state); if (data.ManyValue == null) { @@ -62,7 +62,7 @@ protected static void AssertDataHasManyValue(SingleOrManyData data, Reques protected static void AssertObjectIsNotNull([SysNotNull] T? value, RequestAdapterState state) where T : class { - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(state); if (value is null) { diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentAdapter.cs index ec9842b271..f5b514b202 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentAdapter.cs @@ -16,10 +16,10 @@ public DocumentAdapter(IJsonApiRequest request, ITargetedFields targetedFields, IDocumentInResourceOrRelationshipRequestAdapter documentInResourceOrRelationshipRequestAdapter, IDocumentInOperationsRequestAdapter documentInOperationsRequestAdapter) { - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(targetedFields); - ArgumentGuard.NotNull(documentInResourceOrRelationshipRequestAdapter); - ArgumentGuard.NotNull(documentInOperationsRequestAdapter); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(targetedFields); + ArgumentNullException.ThrowIfNull(documentInResourceOrRelationshipRequestAdapter); + ArgumentNullException.ThrowIfNull(documentInOperationsRequestAdapter); _request = request; _targetedFields = targetedFields; @@ -30,7 +30,7 @@ public DocumentAdapter(IJsonApiRequest request, ITargetedFields targetedFields, /// public object? Convert(Document document) { - ArgumentGuard.NotNull(document); + ArgumentNullException.ThrowIfNull(document); using var adapterState = new RequestAdapterState(_request, _targetedFields); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInOperationsRequestAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInOperationsRequestAdapter.cs index 7187ef0398..9c2aaaaf5e 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInOperationsRequestAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInOperationsRequestAdapter.cs @@ -13,8 +13,8 @@ public sealed class DocumentInOperationsRequestAdapter : BaseAdapter, IDocumentI public DocumentInOperationsRequestAdapter(IJsonApiOptions options, IAtomicOperationObjectAdapter atomicOperationObjectAdapter) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(atomicOperationObjectAdapter); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(atomicOperationObjectAdapter); _options = options; _atomicOperationObjectAdapter = atomicOperationObjectAdapter; @@ -23,8 +23,8 @@ public DocumentInOperationsRequestAdapter(IJsonApiOptions options, IAtomicOperat /// public IList Convert(Document document, RequestAdapterState state) { - ArgumentGuard.NotNull(document); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(document); + ArgumentNullException.ThrowIfNull(state); AssertHasOperations(document.Operations, state); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInResourceOrRelationshipRequestAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInResourceOrRelationshipRequestAdapter.cs index f6acf6212a..48b0c2c5f6 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInResourceOrRelationshipRequestAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/DocumentInResourceOrRelationshipRequestAdapter.cs @@ -15,9 +15,9 @@ public sealed class DocumentInResourceOrRelationshipRequestAdapter : IDocumentIn public DocumentInResourceOrRelationshipRequestAdapter(IJsonApiOptions options, IResourceDataAdapter resourceDataAdapter, IRelationshipDataAdapter relationshipDataAdapter) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(resourceDataAdapter); - ArgumentGuard.NotNull(relationshipDataAdapter); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(resourceDataAdapter); + ArgumentNullException.ThrowIfNull(relationshipDataAdapter); _options = options; _resourceDataAdapter = resourceDataAdapter; @@ -27,8 +27,8 @@ public DocumentInResourceOrRelationshipRequestAdapter(IJsonApiOptions options, I /// public object? Convert(Document document, RequestAdapterState state) { - ArgumentGuard.NotNull(document); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(document); + ArgumentNullException.ThrowIfNull(state); state.WritableTargetedFields = new TargetedFields(); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/RelationshipDataAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/RelationshipDataAdapter.cs index 02b3e80e43..a488e727af 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/RelationshipDataAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/RelationshipDataAdapter.cs @@ -13,7 +13,7 @@ public sealed class RelationshipDataAdapter : BaseAdapter, IRelationshipDataAdap public RelationshipDataAdapter(IResourceIdentifierObjectAdapter resourceIdentifierObjectAdapter) { - ArgumentGuard.NotNull(resourceIdentifierObjectAdapter); + ArgumentNullException.ThrowIfNull(resourceIdentifierObjectAdapter); _resourceIdentifierObjectAdapter = resourceIdentifierObjectAdapter; } @@ -60,8 +60,8 @@ private static SingleOrManyData ToIdentifierData(Singl public object? Convert(SingleOrManyData data, RelationshipAttribute relationship, bool useToManyElementType, RequestAdapterState state) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(state); AssertHasData(data, state); using IDisposable _ = state.Position.PushElement("data"); diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterPosition.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterPosition.cs index 4c047afaea..da3ef481b5 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterPosition.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterPosition.cs @@ -21,7 +21,7 @@ public RequestAdapterPosition() public IDisposable PushElement(string name) { - ArgumentGuard.NotNullNorWhitespace(name); + ArgumentException.ThrowIfNullOrWhiteSpace(name); _stack.Push($"/{name}"); return _disposable; diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterState.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterState.cs index e0c8a0d1c6..089bd48bdf 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterState.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/RequestAdapterState.cs @@ -24,8 +24,8 @@ public sealed class RequestAdapterState : IDisposable public RequestAdapterState(IJsonApiRequest request, ITargetedFields targetedFields) { - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(targetedFields); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(targetedFields); InjectableRequest = request; InjectableTargetedFields = targetedFields; diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataAdapter.cs index 4717436085..91f745327d 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataAdapter.cs @@ -12,8 +12,8 @@ public class ResourceDataAdapter : BaseAdapter, IResourceDataAdapter public ResourceDataAdapter(IResourceDefinitionAccessor resourceDefinitionAccessor, IResourceObjectAdapter resourceObjectAdapter) { - ArgumentGuard.NotNull(resourceDefinitionAccessor); - ArgumentGuard.NotNull(resourceObjectAdapter); + ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor); + ArgumentNullException.ThrowIfNull(resourceObjectAdapter); _resourceDefinitionAccessor = resourceDefinitionAccessor; _resourceObjectAdapter = resourceObjectAdapter; @@ -22,8 +22,8 @@ public ResourceDataAdapter(IResourceDefinitionAccessor resourceDefinitionAccesso /// public IIdentifiable Convert(SingleOrManyData data, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); AssertHasData(data, state); @@ -42,8 +42,8 @@ public IIdentifiable Convert(SingleOrManyData data, ResourceIden protected virtual (IIdentifiable resource, ResourceType resourceType) ConvertResourceObject(SingleOrManyData data, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); return _resourceObjectAdapter.Convert(data.SingleValue!, requirements, state); } diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataInOperationsRequestAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataInOperationsRequestAdapter.cs index 004363cd7f..30deb3c9ba 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataInOperationsRequestAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceDataInOperationsRequestAdapter.cs @@ -11,8 +11,8 @@ public sealed class ResourceDataInOperationsRequestAdapter(IResourceDefinitionAc protected override (IIdentifiable resource, ResourceType resourceType) ConvertResourceObject(SingleOrManyData data, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); // This override ensures that we enrich IJsonApiRequest before calling into IResourceDefinition, so it is ready for consumption there. diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentifierObjectAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentifierObjectAdapter.cs index bc9d380388..05e2bcdafb 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentifierObjectAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentifierObjectAdapter.cs @@ -11,9 +11,9 @@ public sealed class ResourceIdentifierObjectAdapter(IResourceGraph resourceGraph /// public IIdentifiable Convert(ResourceIdentifierObject resourceIdentifierObject, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(resourceIdentifierObject); - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(resourceIdentifierObject); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); (IIdentifiable resource, _) = ConvertResourceIdentity(resourceIdentifierObject, requirements, state); return resource; diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentityAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentityAdapter.cs index 44e56cce99..d0def4e9cd 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentityAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentityAdapter.cs @@ -18,8 +18,8 @@ public abstract class ResourceIdentityAdapter : BaseAdapter protected ResourceIdentityAdapter(IResourceGraph resourceGraph, IResourceFactory resourceFactory) { - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(resourceFactory); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(resourceFactory); _resourceGraph = resourceGraph; _resourceFactory = resourceFactory; @@ -28,9 +28,9 @@ protected ResourceIdentityAdapter(IResourceGraph resourceGraph, IResourceFactory protected (IIdentifiable resource, ResourceType resourceType) ConvertResourceIdentity(ResourceIdentity identity, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(identity); - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(identity); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); ResourceType resourceType = ResolveType(identity, requirements, state); IIdentifiable resource = CreateResource(identity, requirements, resourceType, state); @@ -238,9 +238,9 @@ private void AssignStringId(ResourceIdentity identity, IIdentifiable resource, R protected static void AssertIsKnownRelationship([NotNull] RelationshipAttribute? relationship, string relationshipName, ResourceType resourceType, RequestAdapterState state) { - ArgumentGuard.NotNull(relationshipName); - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(relationshipName); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(state); if (relationship == null) { @@ -251,8 +251,8 @@ protected static void AssertIsKnownRelationship([NotNull] RelationshipAttribute? protected internal static void AssertToManyInAddOrRemoveRelationship(RelationshipAttribute relationship, RequestAdapterState state) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(state); bool requireToManyRelationship = state.Request.WriteOperation is WriteOperationKind.AddToRelationship or WriteOperationKind.RemoveFromRelationship; diff --git a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceObjectAdapter.cs b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceObjectAdapter.cs index 1b85b35336..5f9b4dd05c 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceObjectAdapter.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceObjectAdapter.cs @@ -17,8 +17,8 @@ public ResourceObjectAdapter(IResourceGraph resourceGraph, IResourceFactory reso IRelationshipDataAdapter relationshipDataAdapter) : base(resourceGraph, resourceFactory) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(relationshipDataAdapter); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(relationshipDataAdapter); _options = options; _relationshipDataAdapter = relationshipDataAdapter; @@ -28,9 +28,9 @@ public ResourceObjectAdapter(IResourceGraph resourceGraph, IResourceFactory reso public (IIdentifiable resource, ResourceType resourceType) Convert(ResourceObject resourceObject, ResourceIdentityRequirements requirements, RequestAdapterState state) { - ArgumentGuard.NotNull(resourceObject); - ArgumentGuard.NotNull(requirements); - ArgumentGuard.NotNull(state); + ArgumentNullException.ThrowIfNull(resourceObject); + ArgumentNullException.ThrowIfNull(requirements); + ArgumentNullException.ThrowIfNull(state); (IIdentifiable resource, ResourceType resourceType) = ConvertResourceIdentity(resourceObject, requirements, state); diff --git a/src/JsonApiDotNetCore/Serialization/Request/JsonApiReader.cs b/src/JsonApiDotNetCore/Serialization/Request/JsonApiReader.cs index 2d5fd0a66b..f565395969 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/JsonApiReader.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/JsonApiReader.cs @@ -24,9 +24,9 @@ public sealed partial class JsonApiReader : IJsonApiReader public JsonApiReader(IJsonApiOptions options, IDocumentAdapter documentAdapter, ILogger logger) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(documentAdapter); - ArgumentGuard.NotNull(logger); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(documentAdapter); + ArgumentNullException.ThrowIfNull(logger); _options = options; _documentAdapter = documentAdapter; @@ -36,7 +36,7 @@ public JsonApiReader(IJsonApiOptions options, IDocumentAdapter documentAdapter, /// public async Task ReadAsync(HttpRequest httpRequest) { - ArgumentGuard.NotNull(httpRequest); + ArgumentNullException.ThrowIfNull(httpRequest); string requestBody = await ReceiveRequestBodyAsync(httpRequest); diff --git a/src/JsonApiDotNetCore/Serialization/Request/JsonInvalidAttributeInfo.cs b/src/JsonApiDotNetCore/Serialization/Request/JsonInvalidAttributeInfo.cs index 2fcb31daa1..4004e83de9 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/JsonInvalidAttributeInfo.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/JsonInvalidAttributeInfo.cs @@ -16,8 +16,8 @@ internal sealed class JsonInvalidAttributeInfo public JsonInvalidAttributeInfo(string attributeName, Type attributeType, string? jsonValue, JsonValueKind jsonType) { - ArgumentGuard.NotNull(attributeName); - ArgumentGuard.NotNull(attributeType); + ArgumentNullException.ThrowIfNull(attributeName); + ArgumentNullException.ThrowIfNull(attributeType); AttributeName = attributeName; AttributeType = attributeType; diff --git a/src/JsonApiDotNetCore/Serialization/Request/ModelConversionException.cs b/src/JsonApiDotNetCore/Serialization/Request/ModelConversionException.cs index cf2428129d..02db72573d 100644 --- a/src/JsonApiDotNetCore/Serialization/Request/ModelConversionException.cs +++ b/src/JsonApiDotNetCore/Serialization/Request/ModelConversionException.cs @@ -18,7 +18,7 @@ public sealed class ModelConversionException : Exception public ModelConversionException(RequestAdapterPosition position, string? genericMessage, string? specificMessage, HttpStatusCode? statusCode = null) : base(genericMessage) { - ArgumentGuard.NotNull(position); + ArgumentNullException.ThrowIfNull(position); GenericMessage = genericMessage; SpecificMessage = specificMessage; diff --git a/src/JsonApiDotNetCore/Serialization/Response/ETagGenerator.cs b/src/JsonApiDotNetCore/Serialization/Response/ETagGenerator.cs index d5aefb1fee..e88d9c17d4 100644 --- a/src/JsonApiDotNetCore/Serialization/Response/ETagGenerator.cs +++ b/src/JsonApiDotNetCore/Serialization/Response/ETagGenerator.cs @@ -9,7 +9,7 @@ internal sealed class ETagGenerator : IETagGenerator public ETagGenerator(IFingerprintGenerator fingerprintGenerator) { - ArgumentGuard.NotNull(fingerprintGenerator); + ArgumentNullException.ThrowIfNull(fingerprintGenerator); _fingerprintGenerator = fingerprintGenerator; } diff --git a/src/JsonApiDotNetCore/Serialization/Response/FingerprintGenerator.cs b/src/JsonApiDotNetCore/Serialization/Response/FingerprintGenerator.cs index 5baef6c086..61f3349df3 100644 --- a/src/JsonApiDotNetCore/Serialization/Response/FingerprintGenerator.cs +++ b/src/JsonApiDotNetCore/Serialization/Response/FingerprintGenerator.cs @@ -18,7 +18,7 @@ private static uint ToLookupEntry(int index) /// public string Generate(IEnumerable elements) { - ArgumentGuard.NotNull(elements); + ArgumentNullException.ThrowIfNull(elements); using var hasher = IncrementalHash.CreateHash(HashAlgorithmName.MD5); diff --git a/src/JsonApiDotNetCore/Serialization/Response/JsonApiWriter.cs b/src/JsonApiDotNetCore/Serialization/Response/JsonApiWriter.cs index dad82f7c48..67bb61213b 100644 --- a/src/JsonApiDotNetCore/Serialization/Response/JsonApiWriter.cs +++ b/src/JsonApiDotNetCore/Serialization/Response/JsonApiWriter.cs @@ -29,12 +29,12 @@ public sealed partial class JsonApiWriter : IJsonApiWriter public JsonApiWriter(IJsonApiRequest request, IJsonApiOptions options, IResponseModelAdapter responseModelAdapter, IExceptionHandler exceptionHandler, IETagGenerator eTagGenerator, ILogger logger) { - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(responseModelAdapter); - ArgumentGuard.NotNull(exceptionHandler); - ArgumentGuard.NotNull(eTagGenerator); - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(logger); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(responseModelAdapter); + ArgumentNullException.ThrowIfNull(exceptionHandler); + ArgumentNullException.ThrowIfNull(eTagGenerator); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(logger); _request = request; _options = options; @@ -47,7 +47,7 @@ public JsonApiWriter(IJsonApiRequest request, IJsonApiOptions options, IResponse /// public async Task WriteAsync(object? model, HttpContext httpContext) { - ArgumentGuard.NotNull(httpContext); + ArgumentNullException.ThrowIfNull(httpContext); if (model == null && !CanWriteBody((HttpStatusCode)httpContext.Response.StatusCode)) { diff --git a/src/JsonApiDotNetCore/Serialization/Response/LinkBuilder.cs b/src/JsonApiDotNetCore/Serialization/Response/LinkBuilder.cs index 6d85052177..b7f200dd48 100644 --- a/src/JsonApiDotNetCore/Serialization/Response/LinkBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Response/LinkBuilder.cs @@ -56,13 +56,13 @@ public LinkBuilder(IJsonApiOptions options, IJsonApiRequest request, IPagination LinkGenerator linkGenerator, IControllerResourceMapping controllerResourceMapping, IPaginationParser paginationParser, IDocumentDescriptionLinkProvider documentDescriptionLinkProvider) { - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(paginationContext); - ArgumentGuard.NotNull(linkGenerator); - ArgumentGuard.NotNull(controllerResourceMapping); - ArgumentGuard.NotNull(paginationParser); - ArgumentGuard.NotNull(documentDescriptionLinkProvider); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(paginationContext); + ArgumentNullException.ThrowIfNull(linkGenerator); + ArgumentNullException.ThrowIfNull(controllerResourceMapping); + ArgumentNullException.ThrowIfNull(paginationParser); + ArgumentNullException.ThrowIfNull(documentDescriptionLinkProvider); _options = options; _request = request; @@ -245,8 +245,8 @@ private string GetQueryStringInPaginationLink(int pageOffset, string? pageSizeVa /// public ResourceLinks? GetResourceLinks(ResourceType resourceType, IIdentifiable resource) { - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(resource); var links = new ResourceLinks(); @@ -283,8 +283,8 @@ private bool ShouldIncludeResourceLink(LinkTypes linkType, ResourceType resource /// public RelationshipLinks? GetRelationshipLinks(RelationshipAttribute relationship, IIdentifiable leftResource) { - ArgumentGuard.NotNull(relationship); - ArgumentGuard.NotNull(leftResource); + ArgumentNullException.ThrowIfNull(relationship); + ArgumentNullException.ThrowIfNull(leftResource); var links = new RelationshipLinks(); @@ -332,8 +332,8 @@ private RouteValueDictionary GetRouteValues(string primaryId, string? relationsh protected virtual string? RenderLinkForAction(string? controllerName, string actionName, IDictionary routeValues) { - ArgumentGuard.NotNull(actionName); - ArgumentGuard.NotNull(routeValues); + ArgumentNullException.ThrowIfNull(actionName); + ArgumentNullException.ThrowIfNull(routeValues); if (controllerName == null) { diff --git a/src/JsonApiDotNetCore/Serialization/Response/MetaBuilder.cs b/src/JsonApiDotNetCore/Serialization/Response/MetaBuilder.cs index cafe2fad52..1c3cc604e3 100644 --- a/src/JsonApiDotNetCore/Serialization/Response/MetaBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Response/MetaBuilder.cs @@ -16,9 +16,9 @@ public sealed class MetaBuilder : IMetaBuilder public MetaBuilder(IPaginationContext paginationContext, IJsonApiOptions options, IResponseMeta responseMeta) { - ArgumentGuard.NotNull(paginationContext); - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(responseMeta); + ArgumentNullException.ThrowIfNull(paginationContext); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(responseMeta); _paginationContext = paginationContext; _options = options; @@ -28,7 +28,7 @@ public MetaBuilder(IPaginationContext paginationContext, IJsonApiOptions options /// public void Add(IDictionary values) { - ArgumentGuard.NotNull(values); + ArgumentNullException.ThrowIfNull(values); _meta = values.Keys.Union(_meta.Keys).ToDictionary(key => key, key => values.TryGetValue(key, out object? value) ? value : _meta[key]); } diff --git a/src/JsonApiDotNetCore/Serialization/Response/ResourceObjectTreeNode.cs b/src/JsonApiDotNetCore/Serialization/Response/ResourceObjectTreeNode.cs index e6b61527b2..2ded4ae896 100644 --- a/src/JsonApiDotNetCore/Serialization/Response/ResourceObjectTreeNode.cs +++ b/src/JsonApiDotNetCore/Serialization/Response/ResourceObjectTreeNode.cs @@ -37,9 +37,9 @@ internal sealed class ResourceObjectTreeNode : IEquatable includeElements) { - ArgumentGuard.NotNull(includeElements); + ArgumentNullException.ThrowIfNull(includeElements); ResourceObject? resourceObject = null; @@ -206,8 +206,8 @@ private static ResourceType GetEffectiveResourceType(IIdentifiable resource, Res protected virtual ResourceObject ConvertResource(IIdentifiable resource, ResourceType resourceType, EndpointKind kind) { - ArgumentGuard.NotNull(resource); - ArgumentGuard.NotNull(resourceType); + ArgumentNullException.ThrowIfNull(resource); + ArgumentNullException.ThrowIfNull(resourceType); bool isRelationship = kind == EndpointKind.Relationship; @@ -239,9 +239,9 @@ protected virtual ResourceObject ConvertResource(IIdentifiable resource, Resourc #pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection IImmutableSet fieldSet) { - ArgumentGuard.NotNull(resource); - ArgumentGuard.NotNull(resourceType); - ArgumentGuard.NotNull(fieldSet); + ArgumentNullException.ThrowIfNull(resource); + ArgumentNullException.ThrowIfNull(resourceType); + ArgumentNullException.ThrowIfNull(fieldSet); var attrMap = new Dictionary(resourceType.Attributes.Count); diff --git a/src/JsonApiDotNetCore/Services/AsyncCollectionExtensions.cs b/src/JsonApiDotNetCore/Services/AsyncCollectionExtensions.cs index 31dc56bbec..83ba8902a2 100644 --- a/src/JsonApiDotNetCore/Services/AsyncCollectionExtensions.cs +++ b/src/JsonApiDotNetCore/Services/AsyncCollectionExtensions.cs @@ -7,8 +7,8 @@ public static class AsyncCollectionExtensions { public static async Task AddRangeAsync(this ICollection source, IAsyncEnumerable elementsToAdd, CancellationToken cancellationToken = default) { - ArgumentGuard.NotNull(source); - ArgumentGuard.NotNull(elementsToAdd); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(elementsToAdd); await foreach (T missingResource in elementsToAdd.WithCancellation(cancellationToken)) { @@ -18,7 +18,7 @@ public static async Task AddRangeAsync(this ICollection source, IAsyncEnum public static async Task> ToListAsync(this IAsyncEnumerable source, CancellationToken cancellationToken = default) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); List list = []; diff --git a/src/JsonApiDotNetCore/Services/JsonApiResourceService.cs b/src/JsonApiDotNetCore/Services/JsonApiResourceService.cs index 4fa0cdc4f0..de5d3b7b1f 100644 --- a/src/JsonApiDotNetCore/Services/JsonApiResourceService.cs +++ b/src/JsonApiDotNetCore/Services/JsonApiResourceService.cs @@ -34,14 +34,14 @@ public JsonApiResourceService(IResourceRepositoryAccessor repositoryAccessor, IQ IJsonApiOptions options, ILoggerFactory loggerFactory, IJsonApiRequest request, IResourceChangeTracker resourceChangeTracker, IResourceDefinitionAccessor resourceDefinitionAccessor) { - ArgumentGuard.NotNull(repositoryAccessor); - ArgumentGuard.NotNull(queryLayerComposer); - ArgumentGuard.NotNull(paginationContext); - ArgumentGuard.NotNull(options); - ArgumentGuard.NotNull(loggerFactory); - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(resourceChangeTracker); - ArgumentGuard.NotNull(resourceDefinitionAccessor); + ArgumentNullException.ThrowIfNull(repositoryAccessor); + ArgumentNullException.ThrowIfNull(queryLayerComposer); + ArgumentNullException.ThrowIfNull(paginationContext); + ArgumentNullException.ThrowIfNull(options); + ArgumentNullException.ThrowIfNull(loggerFactory); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(resourceChangeTracker); + ArgumentNullException.ThrowIfNull(resourceDefinitionAccessor); _repositoryAccessor = repositoryAccessor; _queryLayerComposer = queryLayerComposer; @@ -106,7 +106,7 @@ public virtual async Task GetAsync([DisallowNull] TId id, Cancellatio relationshipName }); - ArgumentGuard.NotNull(relationshipName); + ArgumentNullException.ThrowIfNull(relationshipName); AssertPrimaryResourceTypeInJsonApiRequestIsNotNull(_request.PrimaryResourceType); AssertHasRelationship(_request.Relationship, relationshipName); @@ -146,7 +146,7 @@ public virtual async Task GetAsync([DisallowNull] TId id, Cancellatio relationshipName }); - ArgumentGuard.NotNull(relationshipName); + ArgumentNullException.ThrowIfNull(relationshipName); AssertPrimaryResourceTypeInJsonApiRequestIsNotNull(_request.PrimaryResourceType); AssertHasRelationship(_request.Relationship, relationshipName); @@ -196,7 +196,7 @@ private async Task RetrieveResourceCountForNonPrimaryEndpointAsync([DisallowNull resource }); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Service - Create resource"); @@ -237,7 +237,7 @@ private async Task RetrieveResourceCountForNonPrimaryEndpointAsync([DisallowNull protected async Task AssertPrimaryResourceDoesNotExistAsync(TResource resource, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); if (!Equals(resource.Id, default(TId))) { @@ -252,7 +252,7 @@ protected async Task AssertPrimaryResourceDoesNotExistAsync(TResource resource, protected virtual async Task InitializeResourceAsync(TResource resourceForDatabase, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(resourceForDatabase); + ArgumentNullException.ThrowIfNull(resourceForDatabase); await _resourceDefinitionAccessor.OnPrepareWriteAsync(resourceForDatabase, WriteOperationKind.CreateResource, cancellationToken); } @@ -264,7 +264,7 @@ private async Task AccurizeResourceTypesInHierarchyToAssignInRelationshipsAsync( protected async Task AssertResourcesToAssignInRelationshipsExistAsync(TResource primaryResource, CancellationToken cancellationToken) { - ArgumentGuard.NotNull(primaryResource); + ArgumentNullException.ThrowIfNull(primaryResource); await ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(primaryResource, false, cancellationToken); } @@ -349,8 +349,8 @@ public virtual async Task AddToToManyRelationshipAsync([DisallowNull] TId leftId rightResourceIds }); - ArgumentGuard.NotNull(relationshipName); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(relationshipName); + ArgumentNullException.ThrowIfNull(rightResourceIds); AssertHasRelationship(_request.Relationship, relationshipName); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Service - Add to to-many relationship"); @@ -455,7 +455,7 @@ private async Task GetForHasManyUpdateAsync(HasManyAttribute hasManyR resource }); - ArgumentGuard.NotNull(resource); + ArgumentNullException.ThrowIfNull(resource); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Service - Update resource"); @@ -499,7 +499,7 @@ public virtual async Task SetRelationshipAsync([DisallowNull] TId leftId, string rightValue }); - ArgumentGuard.NotNull(relationshipName); + ArgumentNullException.ThrowIfNull(relationshipName); AssertHasRelationship(_request.Relationship, relationshipName); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Service - Set relationship"); @@ -570,8 +570,8 @@ public virtual async Task RemoveFromToManyRelationshipAsync([DisallowNull] TId l rightResourceIds }); - ArgumentGuard.NotNull(relationshipName); - ArgumentGuard.NotNull(rightResourceIds); + ArgumentNullException.ThrowIfNull(relationshipName); + ArgumentNullException.ThrowIfNull(rightResourceIds); AssertHasRelationship(_request.Relationship, relationshipName); using IDisposable _ = CodeTimingSessionManager.Current.Measure("Repository - Remove from to-many relationship"); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/MusicTrackReleaseDefinition.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/MusicTrackReleaseDefinition.cs index 84827322ad..0c89c61571 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/MusicTrackReleaseDefinition.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/MusicTrackReleaseDefinition.cs @@ -1,5 +1,4 @@ using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Resources; using Microsoft.Extensions.Primitives; @@ -15,7 +14,7 @@ public sealed class MusicTrackReleaseDefinition : JsonApiResourceDefinition : JsonApiRes protected HitCountingResourceDefinition(IResourceGraph resourceGraph, ResourceDefinitionHitCounter hitCounter) : base(resourceGraph) { - ArgumentGuard.NotNull(hitCounter); + ArgumentNullException.ThrowIfNull(hitCounter); _hitCounter = hitCounter; } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseExpression.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseExpression.cs index bea7ccd2ba..7a4bfa0788 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseExpression.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseExpression.cs @@ -1,5 +1,4 @@ using System.Text; -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings.CustomFunctions.IsUpperCase; @@ -27,7 +26,7 @@ internal sealed class IsUpperCaseExpression : FilterExpression public IsUpperCaseExpression(ResourceFieldChainExpression targetAttribute) { - ArgumentGuard.NotNull(targetAttribute); + ArgumentNullException.ThrowIfNull(targetAttribute); TargetAttribute = targetAttribute; } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthExpression.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthExpression.cs index 727d3ec808..1fcf8b45dd 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthExpression.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthExpression.cs @@ -1,5 +1,4 @@ using System.Text; -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings.CustomFunctions.StringLength; @@ -31,7 +30,7 @@ internal sealed class LengthExpression : FunctionExpression public LengthExpression(ResourceFieldChainExpression targetAttribute) { - ArgumentGuard.NotNull(targetAttribute); + ArgumentNullException.ThrowIfNull(targetAttribute); TargetAttribute = targetAttribute; } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumExpression.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumExpression.cs index 7e137ad3d7..f353c1552b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumExpression.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumExpression.cs @@ -1,5 +1,4 @@ using System.Text; -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings.CustomFunctions.Sum; @@ -38,8 +37,8 @@ internal sealed class SumExpression : FunctionExpression public SumExpression(ResourceFieldChainExpression targetToManyRelationship, QueryExpression selector) { - ArgumentGuard.NotNull(targetToManyRelationship); - ArgumentGuard.NotNull(selector); + ArgumentNullException.ThrowIfNull(targetToManyRelationship); + ArgumentNullException.ThrowIfNull(selector); TargetToManyRelationship = targetToManyRelationship; Selector = selector; diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetExpression.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetExpression.cs index 1adf976257..8229276acd 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetExpression.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetExpression.cs @@ -1,5 +1,4 @@ using System.Text; -using JsonApiDotNetCore; using JsonApiDotNetCore.Queries.Expressions; namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings.CustomFunctions.TimeOffset; @@ -34,7 +33,7 @@ internal sealed class TimeOffsetExpression : FunctionExpression public TimeOffsetExpression(LiteralConstantExpression timeSpanConstant) { - ArgumentGuard.NotNull(timeSpanConstant); + ArgumentNullException.ThrowIfNull(timeSpanConstant); if (timeSpanConstant.TypedValue is not TimeSpan timeSpan) { diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionDbContext.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionDbContext.cs index 57ec534cae..02154d661e 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionDbContext.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionDbContext.cs @@ -1,5 +1,4 @@ using JetBrains.Annotations; -using JsonApiDotNetCore; using Microsoft.EntityFrameworkCore; using TestBuildingBlocks; @@ -16,7 +15,7 @@ public sealed class InjectionDbContext : TestableDbContext public InjectionDbContext(DbContextOptions options, ISystemClock systemClock) : base(options) { - ArgumentGuard.NotNull(systemClock); + ArgumentNullException.ThrowIfNull(systemClock); SystemClock = systemClock; } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionFakers.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionFakers.cs index 28c7d28dd7..ca557f781b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionFakers.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/InjectionFakers.cs @@ -1,5 +1,4 @@ using Bogus; -using JsonApiDotNetCore; using Microsoft.Extensions.DependencyInjection; using TestBuildingBlocks; @@ -20,7 +19,7 @@ internal sealed class InjectionFakers public InjectionFakers(IServiceProvider serviceProvider) { - ArgumentGuard.NotNull(serviceProvider); + ArgumentNullException.ThrowIfNull(serviceProvider); _serviceProvider = serviceProvider; diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceTypeCapturingDefinition.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceTypeCapturingDefinition.cs index bae85f8754..c12cf527b2 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceTypeCapturingDefinition.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceTypeCapturingDefinition.cs @@ -1,5 +1,4 @@ using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Middleware; using JsonApiDotNetCore.Resources; @@ -20,8 +19,8 @@ public sealed class ResourceTypeCapturingDefinition : JsonApiRes public ResourceTypeCapturingDefinition(IResourceGraph resourceGraph, IJsonApiRequest request, ResourceTypeCaptureStore captureStore) : base(resourceGraph) { - ArgumentGuard.NotNull(request); - ArgumentGuard.NotNull(captureStore); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(captureStore); _request = request; _captureStore = captureStore; diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/WheelSortDefinition.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/WheelSortDefinition.cs index 7785622e9e..98b3e0cdaa 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/WheelSortDefinition.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/WheelSortDefinition.cs @@ -1,7 +1,6 @@ using System.Collections.Immutable; using System.ComponentModel; using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Queries.Expressions; using JsonApiDotNetCore.Resources; @@ -19,7 +18,7 @@ public sealed class WheelSortDefinition : JsonApiResourceDefinition public WheelSortDefinition(IResourceGraph resourceGraph, IHttpContextAccessor httpContextAccessor) : base(resourceGraph) { - ArgumentGuard.NotNull(httpContextAccessor); + ArgumentNullException.ThrowIfNull(httpContextAccessor); _httpContextAccessor = httpContextAccessor; } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ZeroKeys/WhiteSpaceAsKeyTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ZeroKeys/WhiteSpaceAsKeyTests.cs index 9e47b3e6ce..249026e82d 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ZeroKeys/WhiteSpaceAsKeyTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ZeroKeys/WhiteSpaceAsKeyTests.cs @@ -1,7 +1,6 @@ using System.Net; using System.Reflection; using FluentAssertions; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Serialization.Objects; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -604,7 +603,7 @@ private sealed class PreserveWhitespaceModelMetadataProvider : ModelMetadataProv public PreserveWhitespaceModelMetadataProvider(ModelMetadataProvider innerProvider) { - ArgumentGuard.NotNull(innerProvider); + ArgumentNullException.ThrowIfNull(innerProvider); _innerProvider = innerProvider; } diff --git a/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs index 1249cd5dfa..1bf13394b5 100644 --- a/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs @@ -1,6 +1,5 @@ using FluentAssertions; using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Controllers.Annotations; using JsonApiDotNetCore.Queries; @@ -148,7 +147,7 @@ private sealed class SomeSingletonService // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local public SomeSingletonService(SomeScopedService scopedService) { - ArgumentGuard.NotNull(scopedService); + ArgumentNullException.ThrowIfNull(scopedService); } } @@ -161,7 +160,7 @@ private sealed class CircularServiceA // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local public CircularServiceA(CircularServiceB serviceB) { - ArgumentGuard.NotNull(serviceB); + ArgumentNullException.ThrowIfNull(serviceB); } } @@ -171,7 +170,7 @@ private sealed class CircularServiceB // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local public CircularServiceB(CircularServiceA serviceA) { - ArgumentGuard.NotNull(serviceA); + ArgumentNullException.ThrowIfNull(serviceA); } } diff --git a/test/JsonApiDotNetCoreTests/UnitTests/Controllers/DefaultOperationFilterTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/Controllers/DefaultOperationFilterTests.cs index d977518940..66560fdf7b 100644 --- a/test/JsonApiDotNetCoreTests/UnitTests/Controllers/DefaultOperationFilterTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/Controllers/DefaultOperationFilterTests.cs @@ -1,6 +1,5 @@ using FluentAssertions; using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.AtomicOperations; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Controllers; @@ -85,7 +84,7 @@ private sealed class FakeOperationFilter : DefaultOperationFilter public FakeOperationFilter(Func isResourceTypeEnabled) { - ArgumentGuard.NotNull(isResourceTypeEnabled); + ArgumentNullException.ThrowIfNull(isResourceTypeEnabled); _isResourceTypeEnabled = isResourceTypeEnabled; } diff --git a/test/JsonApiDotNetCoreTests/UnitTests/Serialization/Extensions/ResourceObjectConverterTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/Serialization/Extensions/ResourceObjectConverterTests.cs index f87ded5c1b..266874cdf9 100644 --- a/test/JsonApiDotNetCoreTests/UnitTests/Serialization/Extensions/ResourceObjectConverterTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/Serialization/Extensions/ResourceObjectConverterTests.cs @@ -2,7 +2,6 @@ using System.Text.Json; using FluentAssertions; using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Middleware; using JsonApiDotNetCore.Resources; @@ -411,8 +410,8 @@ private sealed class ExtensionAwareResourceObjectConverter : ResourceObjectConve public ExtensionAwareResourceObjectConverter(IResourceGraph resourceGraph, JsonApiRequestAccessor requestAccessor) : base(resourceGraph) { - ArgumentGuard.NotNull(resourceGraph); - ArgumentGuard.NotNull(requestAccessor); + ArgumentNullException.ThrowIfNull(resourceGraph); + ArgumentNullException.ThrowIfNull(requestAccessor); _resourceGraph = resourceGraph; _requestAccessor = requestAccessor; @@ -478,7 +477,7 @@ private sealed class JsonApiRequestAccessor public JsonApiRequestAccessor(IJsonApiRequest request) { - ArgumentGuard.NotNull(request); + ArgumentNullException.ThrowIfNull(request); Request = request; } diff --git a/test/TestBuildingBlocks/CapturingLoggerProvider.cs b/test/TestBuildingBlocks/CapturingLoggerProvider.cs index 20503c4248..07366f5db1 100644 --- a/test/TestBuildingBlocks/CapturingLoggerProvider.cs +++ b/test/TestBuildingBlocks/CapturingLoggerProvider.cs @@ -1,5 +1,4 @@ using JetBrains.Annotations; -using JsonApiDotNetCore; using Microsoft.Extensions.Logging; namespace TestBuildingBlocks; @@ -29,14 +28,14 @@ public CapturingLoggerProvider(LogLevel minimumLevel) public CapturingLoggerProvider(Func filter) { - ArgumentGuard.NotNull(filter); + ArgumentNullException.ThrowIfNull(filter); _filter = filter; } public ILogger CreateLogger(string categoryName) { - ArgumentGuard.NotNullNorEmpty(categoryName); + ArgumentException.ThrowIfNullOrEmpty(categoryName); return new CapturingLogger(this, categoryName, _filter); } diff --git a/test/TestBuildingBlocks/MarkedText.cs b/test/TestBuildingBlocks/MarkedText.cs index f0935b0c2a..003fd0a24f 100644 --- a/test/TestBuildingBlocks/MarkedText.cs +++ b/test/TestBuildingBlocks/MarkedText.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using JetBrains.Annotations; -using JsonApiDotNetCore; namespace TestBuildingBlocks; @@ -14,7 +13,7 @@ public sealed class MarkedText public MarkedText(string source, char marker) { - ArgumentGuard.NotNull(source); + ArgumentNullException.ThrowIfNull(source); Source = source; Position = GetPositionFromMarker(marker); diff --git a/test/TestBuildingBlocks/ServiceCollectionExtensions.cs b/test/TestBuildingBlocks/ServiceCollectionExtensions.cs index 2a11397f69..8e5102fa23 100644 --- a/test/TestBuildingBlocks/ServiceCollectionExtensions.cs +++ b/test/TestBuildingBlocks/ServiceCollectionExtensions.cs @@ -1,5 +1,4 @@ using System.Reflection; -using JsonApiDotNetCore; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; @@ -10,7 +9,7 @@ internal static class ServiceCollectionExtensions { public static void ReplaceControllers(this IServiceCollection services, TestControllerProvider provider) { - ArgumentGuard.NotNull(services); + ArgumentNullException.ThrowIfNull(services); services.AddMvcCore().ConfigureApplicationPartManager(manager => { diff --git a/test/TestBuildingBlocks/XUnitLoggerProvider.cs b/test/TestBuildingBlocks/XUnitLoggerProvider.cs index e264a9bf4a..a6214032af 100644 --- a/test/TestBuildingBlocks/XUnitLoggerProvider.cs +++ b/test/TestBuildingBlocks/XUnitLoggerProvider.cs @@ -1,5 +1,4 @@ using System.Text; -using JsonApiDotNetCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Xunit.Abstractions; @@ -15,7 +14,7 @@ public sealed class XUnitLoggerProvider : ILoggerProvider public XUnitLoggerProvider(ITestOutputHelper testOutputHelper, string? categoryPrefixFilter, LogOutputFields outputFields = LogOutputFields.All) { - ArgumentGuard.NotNull(testOutputHelper); + ArgumentNullException.ThrowIfNull(testOutputHelper); _testOutputHelper = testOutputHelper; _categoryPrefixFilter = categoryPrefixFilter; @@ -24,7 +23,7 @@ public XUnitLoggerProvider(ITestOutputHelper testOutputHelper, string? categoryP public ILogger CreateLogger(string categoryName) { - ArgumentGuard.NotNullNorEmpty(categoryName); + ArgumentException.ThrowIfNullOrEmpty(categoryName); if (_categoryPrefixFilter == null || categoryName.StartsWith(_categoryPrefixFilter, StringComparison.Ordinal)) { diff --git a/test/UnitTests/Models/ResourceConstructionExpressionTests.cs b/test/UnitTests/Models/ResourceConstructionExpressionTests.cs index bfa4e97e32..d8345b5de3 100644 --- a/test/UnitTests/Models/ResourceConstructionExpressionTests.cs +++ b/test/UnitTests/Models/ResourceConstructionExpressionTests.cs @@ -2,7 +2,6 @@ using System.Linq.Expressions; using FluentAssertions; using JetBrains.Annotations; -using JsonApiDotNetCore; using JsonApiDotNetCore.Resources; using TestBuildingBlocks; using Xunit; @@ -52,7 +51,7 @@ private sealed class ResourceWithStringConstructor : Identifiable public ResourceWithStringConstructor(string text) { - ArgumentGuard.NotNullNorEmpty(text); + ArgumentException.ThrowIfNullOrEmpty(text); Text = text; }