Skip to content

Commit

Permalink
Address new net9 analyzer warnings (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin authored Sep 11, 2024
1 parent 6110800 commit 3a342aa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
17 changes: 8 additions & 9 deletions benchmarks/Benchmark.Behaviors/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class DirectTimingBehavior(
SomeHandlerClass handler
)
{
private TimeSpan _elapsed;
public TimeSpan Elapsed { get; private set; }

public async ValueTask<SomeResponse> HandleAsync(
SomeRequest request,
Expand All @@ -19,15 +19,15 @@ CancellationToken cancellationToken
{
var sw = Stopwatch.StartNew();
var response = await handler.Handle(request, cancellationToken);
_elapsed = sw.Elapsed;
Elapsed = sw.Elapsed;
return response;
}
}

public sealed class IhTimingBehavior<TRequest, TResponse>
: Behavior<TRequest, TResponse>
{
private TimeSpan _elapsed;
public TimeSpan Elapsed { get; private set; }

public override async ValueTask<TResponse> HandleAsync(
TRequest request,
Expand All @@ -36,7 +36,7 @@ CancellationToken cancellationToken
{
var sw = Stopwatch.StartNew();
var response = await Next(request, cancellationToken);
_elapsed = sw.Elapsed;
Elapsed = sw.Elapsed;
return response;
}
}
Expand All @@ -46,7 +46,7 @@ public sealed class MTimingBehavior<TRequest, TResponse>
MediatR.IPipelineBehavior<TRequest, TResponse>
where TRequest : Mediator.IRequest<TResponse>, MediatR.IRequest<TResponse>
{
private TimeSpan _elapsed;
public TimeSpan Elapsed { get; private set; }

async ValueTask<TResponse> Mediator.IPipelineBehavior<TRequest, TResponse>.Handle(
TRequest message,
Expand All @@ -55,7 +55,7 @@ async ValueTask<TResponse> Mediator.IPipelineBehavior<TRequest, TResponse>.Handl
{
var sw = Stopwatch.StartNew();
var response = await next(message, cancellationToken);
_elapsed = sw.Elapsed;
Elapsed = sw.Elapsed;
return response;
}

Expand All @@ -66,7 +66,7 @@ async Task<TResponse> MediatR.IPipelineBehavior<TRequest, TResponse>.Handle(
{
var sw = Stopwatch.StartNew();
var response = await next();
_elapsed = sw.Elapsed;
Elapsed = sw.Elapsed;
return response;
}
}
Expand Down Expand Up @@ -159,8 +159,7 @@ public void Setup()
);

_ = services.AddMediatR(
cfg => cfg.RegisterServicesFromAssemblyContaining(
typeof(SomeRequest))
cfg => cfg.RegisterServicesFromAssemblyContaining<SomeRequest>()
);
_ = services.AddScoped(
typeof(MediatR.IPipelineBehavior<,>),
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/Benchmark.Large/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public void Setup()

_ = services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime.Scoped);
_ = services.AddMediatR(
cfg => cfg.RegisterServicesFromAssemblyContaining(
typeof(SomeRequest))
cfg => cfg.RegisterServicesFromAssemblyContaining<SomeRequest>()
);

_serviceProvider = services.BuildServiceProvider();
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/Benchmark.Simple/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public void Setup()

_ = services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime.Scoped);
_ = services.AddMediatR(
cfg => cfg.RegisterServicesFromAssemblyContaining(
typeof(SomeRequest))
cfg => cfg.RegisterServicesFromAssemblyContaining<SomeRequest>()
);

_serviceProvider = services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ public static class ReferenceAssemblyHelpers
{
public static IEnumerable<MetadataReference> GetAdditionalReferences(this DriverReferenceAssemblies assemblies)
{
ArgumentNullException.ThrowIfNull(assemblies);

List<MetadataReference> references =
[
MetadataReference.CreateFromFile("./Immediate.Handlers.Shared.dll"),
];
[
MetadataReference.CreateFromFile("./Immediate.Handlers.Shared.dll"),
];

if (assemblies is DriverReferenceAssemblies.Normal)
return references;
Expand Down
56 changes: 30 additions & 26 deletions tests/Immediate.Handlers.Tests/Immediate.Handlers.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.Net80" />
<PackageReference Include="coverlet.collector" PrivateAssets="All" />
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Verify.SourceGenerators" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<NoWarn>$(NoWarn);NU1903</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../src/Immediate.Handlers.Shared/Immediate.Handlers.Shared.csproj" />
<ProjectReference Include="../../src/Immediate.Handlers.Analyzers/Immediate.Handlers.Analyzers.csproj" />
<ProjectReference Include="../../src/Immediate.Handlers.CodeFixes/Immediate.Handlers.CodeFixes.csproj" />
<ProjectReference Include="../../src/Immediate.Handlers.Generators/Immediate.Handlers.Generators.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.Net80" />
<PackageReference Include="coverlet.collector" PrivateAssets="All" />
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Verify.SourceGenerators" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<Compile Include="../../src/Immediate.Handlers.Analyzers/DiagnosticIds.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Immediate.Handlers.Shared/Immediate.Handlers.Shared.csproj" />
<ProjectReference Include="../../src/Immediate.Handlers.Analyzers/Immediate.Handlers.Analyzers.csproj" />
<ProjectReference Include="../../src/Immediate.Handlers.CodeFixes/Immediate.Handlers.CodeFixes.csproj" />
<ProjectReference Include="../../src/Immediate.Handlers.Generators/Immediate.Handlers.Generators.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="../../src/Immediate.Handlers.Analyzers/DiagnosticIds.cs" />
</ItemGroup>

</Project>

0 comments on commit 3a342aa

Please sign in to comment.