Skip to content

Commit 4576f89

Browse files
authored
Update analysis level (#7594)
* Update AnalysisLevel * Fix CA2263 * Fix CA2264
1 parent 6ba5d90 commit 4576f89

25 files changed

Lines changed: 44 additions & 56 deletions

src/Custom.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<AnalyzerTargetFramework>netstandard2.0</AnalyzerTargetFramework>
5-
<AnalysisLevel>8.0-minimum</AnalysisLevel>
5+
<AnalysisLevel>10.0-minimum</AnalysisLevel>
66
</PropertyGroup>
77

88
<PropertyGroup>

src/NServiceBus.AcceptanceTesting/Support/SubscriptionBehavior.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task Invoke(ITransportReceiveContext context, Func<ITransportReceiv
2929
endpointName = string.Empty;
3030
}
3131

32-
var intent = (MessageIntent)Enum.Parse(typeof(MessageIntent), context.Message.Headers[Headers.MessageIntent], true);
32+
var intent = Enum.Parse<MessageIntent>(context.Message.Headers[Headers.MessageIntent], true);
3333
if (intent != intentToHandle)
3434
{
3535
return;

src/NServiceBus.AcceptanceTests/Core/AutomaticSubscriptions/When_excluding_event_type_from_autosubscribe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Subscriber() =>
4040
{
4141
c.Pipeline.Register("SubscriptionSpy", new SubscriptionSpy((Context)r.ScenarioContext), "Spies on subscriptions made");
4242
c.AutoSubscribe().DisableFor<EventToExclude>();
43-
c.AutoSubscribe().DisableFor(typeof(EventWithNoPublisher));
43+
c.AutoSubscribe().DisableFor<EventWithNoPublisher>();
4444
},
4545
metadata =>
4646
{

src/NServiceBus.AcceptanceTests/Core/Recoverability/When_configuring_unrecoverable_exception.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public EndpointWithFailingHandler()
4949
{
5050
EndpointSetup<DefaultServer>((config, context) =>
5151
{
52-
config.Recoverability().AddUnrecoverableException(typeof(CustomException));
52+
config.Recoverability().AddUnrecoverableException<CustomException>();
5353
config.Recoverability().Immediate(i => i.NumberOfRetries(2));
5454
config.Recoverability().Delayed(d => d.NumberOfRetries(2));
5555
});

src/NServiceBus.AcceptanceTests/Core/Sagas/When_using_ReplyToOriginator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class MyReplyToOriginatorHandler(Context testContext) : IHandleMessages<MyReplyT
7979
{
8080
public Task Handle(MyReplyToOriginator message, IMessageHandlerContext context)
8181
{
82-
testContext.Intent = (MessageIntent)Enum.Parse(typeof(MessageIntent), context.MessageHeaders[Headers.MessageIntent]);
82+
testContext.Intent = Enum.Parse<MessageIntent>(context.MessageHeaders[Headers.MessageIntent]);
8383
testContext.CorrelationIdOnReply = context.MessageHeaders[Headers.CorrelationId];
8484
return Task.CompletedTask;
8585
}

src/NServiceBus.ContainerTests/When_building_components.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void Resolving_all_components_of_unregistered_types_should_give_empty_lis
9191
InitializeServices(serviceCollection);
9292
using var serviceProvider = serviceCollection.BuildServiceProvider();
9393

94-
Assert.That(serviceProvider.GetServices(typeof(UnregisteredComponent)), Is.Empty);
94+
Assert.That(serviceProvider.GetServices<UnregisteredComponent>(), Is.Empty);
9595
}
9696

9797
[Test]
@@ -112,9 +112,9 @@ public void Resolving_recursive_types_does_not_stack_overflow()
112112

113113
static void InitializeServices(IServiceCollection serviceCollection)
114114
{
115-
serviceCollection.AddSingleton(typeof(SingletonComponent));
116-
serviceCollection.AddTransient(typeof(TransientComponent));
117-
serviceCollection.AddScoped(typeof(ScopedComponent));
115+
serviceCollection.AddSingleton<SingletonComponent>();
116+
serviceCollection.AddTransient<TransientComponent>();
117+
serviceCollection.AddScoped<ScopedComponent>();
118118
serviceCollection.AddSingleton(_ => new SingletonLambdaComponent());
119119
serviceCollection.AddTransient(_ => new TransientLambdaComponent());
120120
serviceCollection.AddScoped(_ => new ScopedLambdaComponent());

src/NServiceBus.ContainerTests/When_disposing_the_builder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public void Should_dispose_all_IDisposable_components()
1414
DisposableComponent.DisposeCalled = false;
1515
AnotherSingletonComponent.DisposeCalled = false;
1616

17-
serviceCollection.AddSingleton(typeof(DisposableComponent));
18-
serviceCollection.AddSingleton(typeof(AnotherSingletonComponent), new AnotherSingletonComponent());
17+
serviceCollection.AddSingleton<DisposableComponent>();
18+
serviceCollection.AddSingleton(new AnotherSingletonComponent());
1919

2020
using var serviceProvider = serviceCollection.BuildServiceProvider();
2121
serviceProvider.GetService(typeof(DisposableComponent));

src/NServiceBus.ContainerTests/When_querying_for_registered_components.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public void Builders_should_not_determine_existence_by_building_components()
3636

3737
static void InitializeBuilder(IServiceCollection c)
3838
{
39-
c.AddTransient(typeof(ExistingComponent));
40-
c.AddTransient(typeof(ExistingComponentWithUnsatisfiedDependency));
39+
c.AddTransient<ExistingComponent>();
40+
c.AddTransient<ExistingComponentWithUnsatisfiedDependency>();
4141
}
4242

4343
public class NonExistingComponent

src/NServiceBus.ContainerTests/When_registering_components.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public class When_registering_components
1414
public void Multiple_registrations_of_the_same_component_should_be_allowed()
1515
{
1616
var serviceCollection = new ServiceCollection();
17-
serviceCollection.AddTransient(typeof(DuplicateClass));
18-
serviceCollection.AddTransient(typeof(DuplicateClass));
17+
serviceCollection.AddTransient<DuplicateClass>();
18+
serviceCollection.AddTransient<DuplicateClass>();
1919

2020
using var serviceProvider = serviceCollection.BuildServiceProvider();
21-
Assert.That(serviceProvider.GetServices(typeof(DuplicateClass)).Count(), Is.EqualTo(2));
21+
Assert.That(serviceProvider.GetServices<DuplicateClass>().Count(), Is.EqualTo(2));
2222
}
2323

2424
[Test]
@@ -36,8 +36,8 @@ public void Should_support_lambdas_that_uses_other_components_registered_later()
3636
public void A_registration_should_be_allowed_to_be_updated()
3737
{
3838
var serviceCollection = new ServiceCollection();
39-
serviceCollection.AddSingleton(typeof(ISingletonComponent), new SingletonComponent());
40-
serviceCollection.AddSingleton(typeof(ISingletonComponent), new AnotherSingletonComponent());
39+
serviceCollection.AddSingleton<ISingletonComponent>(new SingletonComponent());
40+
serviceCollection.AddSingleton<ISingletonComponent>(new AnotherSingletonComponent());
4141

4242
using var serviceProvider = serviceCollection.BuildServiceProvider();
4343
Assert.That(serviceProvider.GetService(typeof(ISingletonComponent)), Is.InstanceOf<AnotherSingletonComponent>());
@@ -48,8 +48,8 @@ public void Register_singleton_should_be_supported()
4848
{
4949
var singleton = new SingletonComponent();
5050
var serviceCollection = new ServiceCollection();
51-
serviceCollection.AddSingleton(typeof(ISingletonComponent), singleton);
52-
serviceCollection.AddSingleton(typeof(SingletonComponent), singleton);
51+
serviceCollection.AddSingleton<ISingletonComponent>(singleton);
52+
serviceCollection.AddSingleton(singleton);
5353

5454
using var serviceProvider = serviceCollection.BuildServiceProvider();
5555
Assert.That(singleton, Is.EqualTo(serviceProvider.GetService(typeof(SingletonComponent))));
@@ -61,9 +61,9 @@ public void Registering_the_same_singleton_for_different_interfaces_should_be_su
6161
{
6262
var serviceCollection = new ServiceCollection();
6363
var singleton = new SingletonThatImplementsToInterfaces();
64-
serviceCollection.AddSingleton(typeof(ISingleton1), singleton);
65-
serviceCollection.AddSingleton(typeof(ISingleton2), singleton);
66-
serviceCollection.AddTransient(typeof(ComponentThatDependsOnMultiSingletons));
64+
serviceCollection.AddSingleton<ISingleton1>(singleton);
65+
serviceCollection.AddSingleton<ISingleton2>(singleton);
66+
serviceCollection.AddTransient<ComponentThatDependsOnMultiSingletons>();
6767

6868
using var serviceProvider = serviceCollection.BuildServiceProvider();
6969
var dependency = (ComponentThatDependsOnMultiSingletons)serviceProvider.GetService(typeof(ComponentThatDependsOnMultiSingletons));
@@ -83,7 +83,7 @@ public void Given_lookupType_should_be_used_as_service_in_the_registration_when_
8383
{
8484
var serviceCollection = new ServiceCollection();
8585
var expected = new InheritedFromSomeClass();
86-
serviceCollection.AddSingleton(typeof(SomeClass), expected);
86+
serviceCollection.AddSingleton<SomeClass>(expected);
8787

8888
using var serviceProvider = serviceCollection.BuildServiceProvider();
8989
Assert.That(serviceProvider.GetService(typeof(SomeClass)), Is.EqualTo(expected));

src/NServiceBus.ContainerTests/When_using_nested_containers.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class When_using_nested_containers
1111
public async Task Scoped__components_should_be_disposed_when_the_child_container_is_disposed()
1212
{
1313
var serviceCollection = new ServiceCollection();
14-
serviceCollection.AddScoped(typeof(ScopedComponent));
14+
serviceCollection.AddScoped<ScopedComponent>();
1515

1616
var serviceProvider = serviceCollection.BuildServiceProvider();
1717
await using (serviceProvider.ConfigureAwait(false))
@@ -30,7 +30,7 @@ public async Task Scoped__components_should_be_disposed_when_the_child_container
3030
public void Scoped_components_should_yield_different_instances_between_parent_and_child_containers()
3131
{
3232
var serviceCollection = new ServiceCollection();
33-
serviceCollection.AddScoped(typeof(ScopedComponent));
33+
serviceCollection.AddScoped<ScopedComponent>();
3434

3535
using var serviceProvider = serviceCollection.BuildServiceProvider();
3636

@@ -47,7 +47,7 @@ public void Scoped_components_should_yield_different_instances_between_parent_an
4747
public void Scoped_components_should_yield_different_instances_between_different_instances_of_child_containers()
4848
{
4949
var serviceCollection = new ServiceCollection();
50-
serviceCollection.AddScoped(typeof(ScopedComponent));
50+
serviceCollection.AddScoped<ScopedComponent>();
5151

5252
using var serviceProvider = serviceCollection.BuildServiceProvider();
5353

@@ -69,7 +69,7 @@ public void Scoped_components_should_yield_different_instances_between_different
6969
public void Transient_components_should_not_be_shared_across_child_containers()
7070
{
7171
var serviceCollection = new ServiceCollection();
72-
serviceCollection.AddTransient(typeof(TransientComponent));
72+
serviceCollection.AddTransient<TransientComponent>();
7373

7474
using var serviceProvider = serviceCollection.BuildServiceProvider();
7575

@@ -92,7 +92,7 @@ public void Transient_components_should_not_be_shared_across_child_containers()
9292
public void Scoped_components_in_the_parent_container_should_be_singletons_in_the_same_child_container()
9393
{
9494
var serviceCollection = new ServiceCollection();
95-
serviceCollection.AddScoped(typeof(ScopedComponent));
95+
serviceCollection.AddScoped<ScopedComponent>();
9696

9797
using var serviceProvider = serviceCollection.BuildServiceProvider();
9898

@@ -109,7 +109,7 @@ public void Scoped_components_in_the_parent_container_should_be_singletons_in_th
109109
public void Scoped_components_built_on_root_container_should_be_singletons_even_with_child_builder_present()
110110
{
111111
var serviceCollection = new ServiceCollection();
112-
serviceCollection.AddScoped(typeof(ScopedComponent));
112+
serviceCollection.AddScoped<ScopedComponent>();
113113

114114
using var serviceProvider = serviceCollection.BuildServiceProvider();
115115

@@ -128,8 +128,8 @@ public void Should_not_dispose_singletons_when_container_goes_out_of_scope()
128128
{
129129
var serviceCollection = new ServiceCollection();
130130
var singletonInMainContainer = new SingletonComponent();
131-
serviceCollection.AddSingleton(typeof(ISingletonComponent), singletonInMainContainer);
132-
serviceCollection.AddScoped(typeof(ComponentThatDependsOfSingleton));
131+
serviceCollection.AddSingleton<ISingletonComponent>(singletonInMainContainer);
132+
serviceCollection.AddScoped<ComponentThatDependsOfSingleton>();
133133

134134
using var serviceProvider = serviceCollection.BuildServiceProvider();
135135

@@ -146,8 +146,8 @@ public void Should_dispose_all_non_singleton_IDisposable_components_in_child_con
146146
var serviceCollection = new ServiceCollection();
147147
DisposableComponent.DisposeCalled = false;
148148
AnotherDisposableComponent.DisposeCalled = false;
149-
serviceCollection.AddSingleton(typeof(AnotherDisposableComponent), new AnotherDisposableComponent());
150-
serviceCollection.AddScoped(typeof(DisposableComponent));
149+
serviceCollection.AddSingleton(new AnotherDisposableComponent());
150+
serviceCollection.AddScoped<DisposableComponent>();
151151

152152

153153
using (var serviceProvider = serviceCollection.BuildServiceProvider())

0 commit comments

Comments
 (0)