Skip to content

Commit 09615ea

Browse files
committed
Fix new CA warnings
1 parent 54b2385 commit 09615ea

File tree

13 files changed

+32
-25
lines changed

13 files changed

+32
-25
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<Nullable>enable</Nullable>
4-
<LangVersion>latest</LangVersion>
4+
<LangVersion>preview</LangVersion>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<IsPackable>false</IsPackable>
77
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>

benchmarks/QueryString/QueryStringParserBenchmarks.cs

Lines changed: 1 addition & 1 deletion
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/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
}
3232
case DatabaseProvider.MySql:
3333
{
34+
// https://github.com/dotnet/roslyn-analyzers/issues/7420
35+
#pragma warning disable CA1849 // Call async methods when in an async method
3436
builder.Services.AddMySql<AppDbContext>(connectionString, ServerVersion.AutoDetect(connectionString),
37+
#pragma warning restore CA1849 // Call async methods when in an async method
3538
optionsAction: options => SetDbContextDebugOptions(options));
3639

3740
break;

src/JsonApiDotNetCore/Middleware/TraceLogWriter.cs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ 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));
31+
Request.PrimaryResourceType.ClrType.Should().Be<TLeft>();
3232
Request.Relationship?.LeftType.ClrType.Should().Be(typeof(TLeft));
3333
}
3434

test/JsonApiDotNetCoreTests/UnitTests/ResourceDefinitions/CreateSortExpressionFromLambdaTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,17 @@ private abstract class FileSystemEntry : Identifiable<long>
364364
public FileSystemEntry Parent { get; set; } = null!;
365365

366366
[HasMany]
367-
public IList<FileSystemEntry> Children { get; set; } = new List<FileSystemEntry>();
367+
public List<FileSystemEntry> Children { get; set; } = [];
368368
}
369369

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

376376
[HasMany]
377-
public IList<FileEntry> Files { get; set; } = new List<FileEntry>();
377+
public List<FileEntry> Files { get; set; } = [];
378378
}
379379

380380
[UsedImplicitly(ImplicitUseTargetFlags.Members)]

test/JsonApiDotNetCoreTests/UnitTests/ResourceGraph/ResourceGraphBuilderTests.cs

Lines changed: 1 addition & 1 deletion
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]

test/TestBuildingBlocks/CapturingLoggerProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public sealed class CapturingLoggerProvider : ILoggerProvider
1010
private static readonly Func<string, LogLevel, bool> DefaultFilter = (_, _) => true;
1111
private readonly Func<string, LogLevel, bool> _filter;
1212

13+
#if NET9_0_OR_GREATER
14+
private readonly Lock _lockObject = new();
15+
#else
1316
private readonly object _lockObject = new();
17+
#endif
1418
private readonly List<LogMessage> _messages = [];
1519

1620
public CapturingLoggerProvider()

test/UnitTests/Graph/TypeLocatorTests.cs

Lines changed: 4 additions & 4 deletions
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)