Skip to content

Commit d568a71

Browse files
authored
Backport fixes for new analyzers in .NET 9 (#1618)
1 parent dc8cbd2 commit d568a71

File tree

12 files changed

+29
-26
lines changed

12 files changed

+29
-26
lines changed

benchmarks/QueryString/QueryStringParserBenchmarks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public QueryStringParserBenchmarks()
3131

3232
var request = new JsonApiRequest
3333
{
34-
PrimaryResourceType = resourceGraph.GetResourceType(typeof(QueryableResource)),
34+
PrimaryResourceType = resourceGraph.GetResourceType<QueryableResource>(),
3535
IsCollection = true
3636
};
3737

src/Examples/DapperExample/Repositories/DapperRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public async Task DeleteAsync(TResource? resourceFromDatabase, [DisallowNull] TI
365365
await _resourceDefinitionAccessor.OnWritingAsync(placeholderResource, WriteOperationKind.DeleteResource, cancellationToken);
366366

367367
var deleteBuilder = new DeleteResourceStatementBuilder(_dataModelService);
368-
DeleteNode deleteNode = deleteBuilder.Build(ResourceType, placeholderResource.Id!);
368+
DeleteNode deleteNode = deleteBuilder.Build(ResourceType, placeholderResource.Id);
369369
CommandDefinition sqlCommand = _dapperFacade.GetSqlCommand(deleteNode, cancellationToken);
370370

371371
await ExecuteInTransactionAsync(async transaction =>

src/JsonApiDotNetCore/Middleware/TraceLogWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public override void Write(Utf8JsonWriter writer, TWrapper value, JsonSerializer
120120

121121
internal sealed partial class TraceLogWriter<T>(ILoggerFactory loggerFactory) : TraceLogWriter
122122
{
123-
private readonly ILogger _logger = loggerFactory.CreateLogger(typeof(T));
123+
private readonly ILogger _logger = loggerFactory.CreateLogger<T>();
124124

125125
public void LogMethodStart(object? parameters = null, [CallerMemberName] string memberName = "")
126126
{

src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public QueryLayer ComposeForUpdate<TId>([DisallowNull] TId id, ResourceType prim
390390
{
391391
ArgumentGuard.NotNull(primaryResourceType);
392392

393-
IImmutableSet<IncludeElementExpression> includeElements = _targetedFields.Relationships
393+
ImmutableHashSet<IncludeElementExpression> includeElements = _targetedFields.Relationships
394394
.Select(relationship => new IncludeElementExpression(relationship)).ToImmutableHashSet();
395395

396396
AttrAttribute primaryIdAttribute = GetIdAttribute(primaryResourceType);

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
114114

115115
PropertyInfo? property = typeof(WorkItem).GetProperty(nameof(Identifiable<object>.Id));
116116
property.ShouldNotBeNull();
117-
property.PropertyType.Should().Be(typeof(int));
117+
property.PropertyType.Should().Be<int>();
118118
}
119119

120120
[Fact]
@@ -162,7 +162,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
162162

163163
PropertyInfo? property = typeof(UserAccount).GetProperty(nameof(Identifiable<object>.Id));
164164
property.ShouldNotBeNull();
165-
property.PropertyType.Should().Be(typeof(long));
165+
property.PropertyType.Should().Be<long>();
166166
}
167167

168168
[Fact]
@@ -207,7 +207,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
207207

208208
PropertyInfo? property = typeof(WorkItemGroup).GetProperty(nameof(Identifiable<object>.Id));
209209
property.ShouldNotBeNull();
210-
property.PropertyType.Should().Be(typeof(Guid));
210+
property.PropertyType.Should().Be<Guid>();
211211
}
212212

213213
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithClientGeneratedIdTests.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8080

8181
PropertyInfo? property = typeof(WorkItemGroup).GetProperty(nameof(Identifiable<object>.Id));
8282
property.ShouldNotBeNull();
83-
property.PropertyType.Should().Be(typeof(Guid));
83+
property.PropertyType.Should().Be<Guid>();
8484
}
8585

8686
[Theory]
@@ -134,7 +134,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
134134

135135
PropertyInfo? property = typeof(WorkItemGroup).GetProperty(nameof(Identifiable<object>.Id));
136136
property.ShouldNotBeNull();
137-
property.PropertyType.Should().Be(typeof(Guid));
137+
property.PropertyType.Should().Be<Guid>();
138138
}
139139

140140
[Theory]
@@ -185,7 +185,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
185185

186186
PropertyInfo? property = typeof(RgbColor).GetProperty(nameof(Identifiable<object>.Id));
187187
property.ShouldNotBeNull();
188-
property.PropertyType.Should().Be(typeof(string));
188+
property.PropertyType.Should().Be<string>();
189189
}
190190

191191
[Theory]
@@ -236,7 +236,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
236236

237237
PropertyInfo? property = typeof(RgbColor).GetProperty(nameof(Identifiable<object>.Id));
238238
property.ShouldNotBeNull();
239-
property.PropertyType.Should().Be(typeof(string));
239+
property.PropertyType.Should().Be<string>();
240240
}
241241

242242
[Theory]
@@ -292,7 +292,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
292292

293293
PropertyInfo? property = typeof(RgbColor).GetProperty(nameof(Identifiable<object>.Id));
294294
property.ShouldNotBeNull();
295-
property.PropertyType.Should().Be(typeof(string));
295+
property.PropertyType.Should().Be<string>();
296296
}
297297

298298
[Theory]
@@ -475,7 +475,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
475475

476476
PropertyInfo? property = typeof(RgbColor).GetProperty(nameof(Identifiable<object>.Id));
477477
property.ShouldNotBeNull();
478-
property.PropertyType.Should().Be(typeof(string));
478+
property.PropertyType.Should().Be<string>();
479479
}
480480

481481
[Theory]

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
327327

328328
PropertyInfo? property = typeof(WorkItemGroup).GetProperty(nameof(Identifiable<object>.Id));
329329
property.ShouldNotBeNull();
330-
property.PropertyType.Should().Be(typeof(Guid));
330+
property.PropertyType.Should().Be<Guid>();
331331
}
332332

333333
[Fact]
@@ -375,7 +375,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
375375

376376
PropertyInfo? property = typeof(RgbColor).GetProperty(nameof(Identifiable<object>.Id));
377377
property.ShouldNotBeNull();
378-
property.PropertyType.Should().Be(typeof(string));
378+
property.PropertyType.Should().Be<string>();
379379
}
380380

381381
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceTypeCaptureStore.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ internal void Reset()
2323

2424
internal void AssertLeftType<TLeft>()
2525
{
26-
LeftDeclaredType.Should().Be(typeof(TLeft));
26+
LeftDeclaredType.Should().Be<TLeft>();
2727
LeftReflectedTypeName.Should().Be(typeof(TLeft).Name);
2828

2929
Request.ShouldNotBeNull();
3030
Request.PrimaryResourceType.ShouldNotBeNull();
31-
Request.PrimaryResourceType.ClrType.Should().Be(typeof(TLeft));
32-
Request.Relationship?.LeftType.ClrType.Should().Be(typeof(TLeft));
31+
Request.PrimaryResourceType.ClrType.Should().Be<TLeft>();
32+
Request.Relationship?.LeftType.ClrType.Should().Be<TLeft>();
3333
}
3434

3535
internal void AssertRightTypes(params Type[] types)

test/JsonApiDotNetCoreTests/UnitTests/ResourceDefinitions/CreateSortExpressionFromLambdaTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,17 @@ private abstract class FileSystemEntry : Identifiable<long>
365365
public FileSystemEntry Parent { get; set; } = null!;
366366

367367
[HasMany]
368-
public IList<FileSystemEntry> Children { get; set; } = new List<FileSystemEntry>();
368+
public List<FileSystemEntry> Children { get; set; } = [];
369369
}
370370

371371
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
372372
private sealed class DirectoryEntry : FileSystemEntry
373373
{
374374
[HasMany]
375-
public IList<DirectoryEntry> Subdirectories { get; set; } = new List<DirectoryEntry>();
375+
public List<DirectoryEntry> Subdirectories { get; set; } = [];
376376

377377
[HasMany]
378-
public IList<FileEntry> Files { get; set; } = new List<FileEntry>();
378+
public List<FileEntry> Files { get; set; } = [];
379379
}
380380

381381
[UsedImplicitly(ImplicitUseTargetFlags.Members)]

test/JsonApiDotNetCoreTests/UnitTests/ResourceGraph/ResourceGraphBuilderTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public void Resolves_correct_type_for_lazy_loading_proxy()
343343
ResourceType resourceType = resourceGraph.GetResourceType(proxy.GetType());
344344

345345
// Assert
346-
resourceType.ClrType.Should().Be(typeof(ResourceOfInt32));
346+
resourceType.ClrType.Should().Be<ResourceOfInt32>();
347347
}
348348

349349
[Fact]
+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using JetBrains.Annotations;
2+
13
namespace UnitTests.Graph;
24

5+
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
36
internal sealed class Implementation : IGenericInterface<int>;

test/UnitTests/Graph/TypeLocatorTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public void GetContainerRegistrationFromAssembly_Gets_Implementation()
2323

2424
// Assert
2525
result.ShouldNotBeNull();
26-
result.Value.implementationType.Should().Be(typeof(Implementation));
27-
result.Value.serviceInterface.Should().Be(typeof(IGenericInterface<int>));
26+
result.Value.implementationType.Should().Be<Implementation>();
27+
result.Value.serviceInterface.Should().Be<IGenericInterface<int>>();
2828
}
2929

3030
[Fact]
@@ -39,7 +39,7 @@ public void GetIdType_Correctly_Identifies_JsonApiResource()
3939
Type? idType = typeLocator.LookupIdType(type);
4040

4141
// Assert
42-
idType.Should().Be(typeof(int));
42+
idType.Should().Be<int>();
4343
}
4444

4545
[Fact]
@@ -71,7 +71,7 @@ public void ResolveResourceDescriptor_Returns_Type_If_Type_Is_IIdentifiable()
7171
// Assert
7272
descriptor.ShouldNotBeNull();
7373
descriptor.ResourceClrType.Should().Be(resourceClrType);
74-
descriptor.IdClrType.Should().Be(typeof(int));
74+
descriptor.IdClrType.Should().Be<int>();
7575
}
7676

7777
[Fact]

0 commit comments

Comments
 (0)