Skip to content

Commit

Permalink
Remove ArrayFactory.Create
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Nov 21, 2023
1 parent 6beb3d9 commit af66d71
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 27 deletions.
11 changes: 8 additions & 3 deletions benchmarks/QueryString/QueryStringParserBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.ComponentModel.Design;
using BenchmarkDotNet.Attributes;
using Benchmarks.Tools;
using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Queries.Parsing;
Expand Down Expand Up @@ -55,8 +54,14 @@ public QueryStringParserBenchmarks()
var paginationParser = new PaginationParser();
var paginationReader = new PaginationQueryStringParameterReader(paginationParser, request, resourceGraph, options);

IQueryStringParameterReader[] readers = ArrayFactory.Create<IQueryStringParameterReader>(includeReader, filterReader, sortReader,
sparseFieldSetReader, paginationReader);
IQueryStringParameterReader[] readers =
[
includeReader,
filterReader,
sortReader,
sparseFieldSetReader,
paginationReader
];

_queryStringReader = new QueryStringReader(options, _queryStringAccessor, readers, NullLoggerFactory.Instance);
}
Expand Down
12 changes: 0 additions & 12 deletions src/JsonApiDotNetCore/ArrayFactory.cs

This file was deleted.

8 changes: 5 additions & 3 deletions src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ private void AddResourceDefinitions(Assembly assembly, ResourceDescriptor resour

private void RegisterImplementations(Assembly assembly, Type interfaceType, ResourceDescriptor resourceDescriptor)
{
Type[] typeArguments = interfaceType.GetTypeInfo().GenericTypeParameters.Length == 2
? ArrayFactory.Create(resourceDescriptor.ResourceClrType, resourceDescriptor.IdClrType)
: ArrayFactory.Create(resourceDescriptor.ResourceClrType);
Type[] typeArguments =
[
resourceDescriptor.ResourceClrType,
resourceDescriptor.IdClrType
];

(Type implementationType, Type serviceInterface)? result = _typeLocator.GetContainerRegistrationFromAssembly(assembly, interfaceType, typeArguments);

Expand Down
7 changes: 6 additions & 1 deletion src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ private abstract class ModelStateKeySegment
private const char Dot = '.';
private const char BracketOpen = '[';
private const char BracketClose = ']';
private static readonly char[] KeySegmentStartTokens = ArrayFactory.Create(Dot, BracketOpen);

private static readonly char[] KeySegmentStartTokens =
[
Dot,
BracketOpen
];

// The right part of the full key, which nested segments are produced from.
private readonly string _nextKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ private static string GetOperationName(bool isAscending, QueryClauseBuilderConte
private static Expression ExtensionMethodCall(Expression source, string operationName, Type keyType, LambdaExpression keySelector,
QueryClauseBuilderContext context)
{
Type[] typeArguments = ArrayFactory.Create(context.LambdaScope.Parameter.Type, keyType);
Type[] typeArguments =
[
context.LambdaScope.Parameter.Type,
keyType
];

return Expression.Call(context.ExtensionType, operationName, typeArguments, source, keySelector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ private static Expression CopyCollectionExtensionMethodCall(Expression source, s

private static Expression SelectExtensionMethodCall(Type extensionType, Expression source, Type elementType, Expression selectBody)
{
Type[] typeArguments = ArrayFactory.Create(elementType, elementType);
Type[] typeArguments =
[
elementType,
elementType
];

return Expression.Call(extensionType, "Select", typeArguments, source, selectBody);
}

Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Resources/ResourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static IIdentifiable CreateWrapperForAbstractType(Type resourceClrType)
Type wrapperClrType = typeof(AbstractResourceWrapper<>).MakeGenericType(descriptor.IdClrType);
ConstructorInfo constructor = wrapperClrType.GetConstructors().Single();

object resource = constructor.Invoke(ArrayFactory.Create<object>(resourceClrType));
object resource = constructor.Invoke([resourceClrType]);
return (IIdentifiable)resource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ public ETagGenerator(IFingerprintGenerator fingerprintGenerator)
/// <inheritdoc />
public EntityTagHeaderValue Generate(string requestUrl, string responseBody)
{
string fingerprint = _fingerprintGenerator.Generate(ArrayFactory.Create(requestUrl, responseBody));
string[] elements =
[
requestUrl,
responseBody
];

string fingerprint = _fingerprintGenerator.Generate(elements);
string eTagValue = $"\"{fingerprint}\"";

return EntityTagHeaderValue.Parse(eTagValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Net;
using FluentAssertions;
using JsonApiDotNetCore;
using JsonApiDotNetCore.Serialization.Objects;
using Microsoft.EntityFrameworkCore;
using TestBuildingBlocks;
Expand Down Expand Up @@ -880,7 +879,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
dbContext.WorkItems.Add(existingWorkItem);
await dbContext.SaveChangesAsync();

existingWorkItem.RelatedFrom = ArrayFactory.Create(existingWorkItem);
existingWorkItem.RelatedFrom = [existingWorkItem];
await dbContext.SaveChangesAsync();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
dbContext.WorkItems.Add(existingWorkItem);
await dbContext.SaveChangesAsync();

existingWorkItem.RelatedFrom = ArrayFactory.Create(existingWorkItem);
existingWorkItem.RelatedFrom = [existingWorkItem];
await dbContext.SaveChangesAsync();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override Task OnWriteSucceededAsync(TResource resource, WriteOperationKin

private void EnsureSnapshot(TResource leftType, IIdentifiable? rightResourceId = null)
{
IIdentifiable[] rightResourceIds = rightResourceId != null ? ArrayFactory.Create(rightResourceId) : Array.Empty<IIdentifiable>();
IIdentifiable[] rightResourceIds = rightResourceId != null ? [rightResourceId] : Array.Empty<IIdentifiable>();

EnsureSnapshot(leftType, rightResourceIds);
}
Expand Down

0 comments on commit af66d71

Please sign in to comment.