Skip to content

Commit af66d71

Browse files
committed
Remove ArrayFactory.Create
1 parent 6beb3d9 commit af66d71

File tree

11 files changed

+42
-27
lines changed

11 files changed

+42
-27
lines changed

benchmarks/QueryString/QueryStringParserBenchmarks.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.ComponentModel.Design;
22
using BenchmarkDotNet.Attributes;
33
using Benchmarks.Tools;
4-
using JsonApiDotNetCore;
54
using JsonApiDotNetCore.Configuration;
65
using JsonApiDotNetCore.Middleware;
76
using JsonApiDotNetCore.Queries.Parsing;
@@ -55,8 +54,14 @@ public QueryStringParserBenchmarks()
5554
var paginationParser = new PaginationParser();
5655
var paginationReader = new PaginationQueryStringParameterReader(paginationParser, request, resourceGraph, options);
5756

58-
IQueryStringParameterReader[] readers = ArrayFactory.Create<IQueryStringParameterReader>(includeReader, filterReader, sortReader,
59-
sparseFieldSetReader, paginationReader);
57+
IQueryStringParameterReader[] readers =
58+
[
59+
includeReader,
60+
filterReader,
61+
sortReader,
62+
sparseFieldSetReader,
63+
paginationReader
64+
];
6065

6166
_queryStringReader = new QueryStringReader(options, _queryStringAccessor, readers, NullLoggerFactory.Instance);
6267
}

src/JsonApiDotNetCore/ArrayFactory.cs

-12
This file was deleted.

src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ private void AddResourceDefinitions(Assembly assembly, ResourceDescriptor resour
152152

153153
private void RegisterImplementations(Assembly assembly, Type interfaceType, ResourceDescriptor resourceDescriptor)
154154
{
155-
Type[] typeArguments = interfaceType.GetTypeInfo().GenericTypeParameters.Length == 2
156-
? ArrayFactory.Create(resourceDescriptor.ResourceClrType, resourceDescriptor.IdClrType)
157-
: ArrayFactory.Create(resourceDescriptor.ResourceClrType);
155+
Type[] typeArguments =
156+
[
157+
resourceDescriptor.ResourceClrType,
158+
resourceDescriptor.IdClrType
159+
];
158160

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

src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ private abstract class ModelStateKeySegment
207207
private const char Dot = '.';
208208
private const char BracketOpen = '[';
209209
private const char BracketClose = ']';
210-
private static readonly char[] KeySegmentStartTokens = ArrayFactory.Create(Dot, BracketOpen);
210+
211+
private static readonly char[] KeySegmentStartTokens =
212+
[
213+
Dot,
214+
BracketOpen
215+
];
211216

212217
// The right part of the full key, which nested segments are produced from.
213218
private readonly string _nextKey;

src/JsonApiDotNetCore/Queries/QueryableBuilding/OrderClauseBuilder.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ private static string GetOperationName(bool isAscending, QueryClauseBuilderConte
5757
private static Expression ExtensionMethodCall(Expression source, string operationName, Type keyType, LambdaExpression keySelector,
5858
QueryClauseBuilderContext context)
5959
{
60-
Type[] typeArguments = ArrayFactory.Create(context.LambdaScope.Parameter.Type, keyType);
60+
Type[] typeArguments =
61+
[
62+
context.LambdaScope.Parameter.Type,
63+
keyType
64+
];
65+
6166
return Expression.Call(context.ExtensionType, operationName, typeArguments, source, keySelector);
6267
}
6368
}

src/JsonApiDotNetCore/Queries/QueryableBuilding/SelectClauseBuilder.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ private static Expression CopyCollectionExtensionMethodCall(Expression source, s
247247

248248
private static Expression SelectExtensionMethodCall(Type extensionType, Expression source, Type elementType, Expression selectBody)
249249
{
250-
Type[] typeArguments = ArrayFactory.Create(elementType, elementType);
250+
Type[] typeArguments =
251+
[
252+
elementType,
253+
elementType
254+
];
255+
251256
return Expression.Call(extensionType, "Select", typeArguments, source, selectBody);
252257
}
253258

src/JsonApiDotNetCore/Resources/ResourceFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private static IIdentifiable CreateWrapperForAbstractType(Type resourceClrType)
5050
Type wrapperClrType = typeof(AbstractResourceWrapper<>).MakeGenericType(descriptor.IdClrType);
5151
ConstructorInfo constructor = wrapperClrType.GetConstructors().Single();
5252

53-
object resource = constructor.Invoke(ArrayFactory.Create<object>(resourceClrType));
53+
object resource = constructor.Invoke([resourceClrType]);
5454
return (IIdentifiable)resource;
5555
}
5656

src/JsonApiDotNetCore/Serialization/Response/ETagGenerator.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ public ETagGenerator(IFingerprintGenerator fingerprintGenerator)
1717
/// <inheritdoc />
1818
public EntityTagHeaderValue Generate(string requestUrl, string responseBody)
1919
{
20-
string fingerprint = _fingerprintGenerator.Generate(ArrayFactory.Create(requestUrl, responseBody));
20+
string[] elements =
21+
[
22+
requestUrl,
23+
responseBody
24+
];
25+
26+
string fingerprint = _fingerprintGenerator.Generate(elements);
2127
string eTagValue = $"\"{fingerprint}\"";
2228

2329
return EntityTagHeaderValue.Parse(eTagValue);

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/ReplaceToManyRelationshipTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Net;
22
using FluentAssertions;
3-
using JsonApiDotNetCore;
43
using JsonApiDotNetCore.Serialization.Objects;
54
using Microsoft.EntityFrameworkCore;
65
using TestBuildingBlocks;
@@ -880,7 +879,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
880879
dbContext.WorkItems.Add(existingWorkItem);
881880
await dbContext.SaveChangesAsync();
882881

883-
existingWorkItem.RelatedFrom = ArrayFactory.Create(existingWorkItem);
882+
existingWorkItem.RelatedFrom = [existingWorkItem];
884883
await dbContext.SaveChangesAsync();
885884
});
886885

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/ReplaceToManyRelationshipTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
965965
dbContext.WorkItems.Add(existingWorkItem);
966966
await dbContext.SaveChangesAsync();
967967

968-
existingWorkItem.RelatedFrom = ArrayFactory.Create(existingWorkItem);
968+
existingWorkItem.RelatedFrom = [existingWorkItem];
969969
await dbContext.SaveChangesAsync();
970970
});
971971

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceTypeCapturingDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override Task OnWriteSucceededAsync(TResource resource, WriteOperationKin
8282

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

8787
EnsureSnapshot(leftType, rightResourceIds);
8888
}

0 commit comments

Comments
 (0)