Skip to content

Commit 6c128c0

Browse files
Fix nullability issues in runner method signatures, fix #2249
1 parent fb7f1be commit 6c128c0

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/BenchmarkDotNet/Running/BenchmarkConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static partial class BenchmarkConverter
1818
{
1919
private const BindingFlags AllMethodsFlags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
2020

21-
public static BenchmarkRunInfo TypeToBenchmarks(Type type, IConfig config = null)
21+
public static BenchmarkRunInfo TypeToBenchmarks(Type type, IConfig? config = null)
2222
{
2323
if (type.IsGenericTypeDefinition)
2424
throw new InvalidBenchmarkDeclarationException($"{type.Name} is generic type definition, use BenchmarkSwitcher for it"); // for "open generic types" should be used BenchmarkSwitcher
@@ -29,7 +29,7 @@ public static BenchmarkRunInfo TypeToBenchmarks(Type type, IConfig config = null
2929
return MethodsToBenchmarksWithFullConfig(type, benchmarkMethods, config);
3030
}
3131

32-
public static BenchmarkRunInfo MethodsToBenchmarks(Type containingType, MethodInfo[] benchmarkMethods, IConfig config = null)
32+
public static BenchmarkRunInfo MethodsToBenchmarks(Type containingType, MethodInfo[] benchmarkMethods, IConfig? config = null)
3333
=> MethodsToBenchmarksWithFullConfig(containingType, GetOrderedBenchmarkMethods(benchmarkMethods), config);
3434

3535
private static MethodInfo[] GetOrderedBenchmarkMethods(MethodInfo[] methods)
@@ -41,7 +41,7 @@ private static MethodInfo[] GetOrderedBenchmarkMethods(MethodInfo[] methods)
4141
.Select(pair => pair.method)
4242
.ToArray();
4343

44-
private static BenchmarkRunInfo MethodsToBenchmarksWithFullConfig(Type type, MethodInfo[] benchmarkMethods, IConfig config)
44+
private static BenchmarkRunInfo MethodsToBenchmarksWithFullConfig(Type type, MethodInfo[] benchmarkMethods, IConfig? config)
4545
{
4646
var allMethods = type.GetMethods(AllMethodsFlags); // benchmarkMethods can be filtered, without Setups, look #564
4747
var configPerType = GetFullTypeConfig(type, config);
@@ -82,7 +82,7 @@ from parameterInstance in parameterInstances
8282
return new BenchmarkRunInfo(orderedBenchmarks, type, configPerType);
8383
}
8484

85-
private static ImmutableConfig GetFullTypeConfig(Type type, IConfig config)
85+
private static ImmutableConfig GetFullTypeConfig(Type type, IConfig? config)
8686
{
8787
config = config ?? DefaultConfig.Instance;
8888

src/BenchmarkDotNet/Running/BenchmarkRunnerDirty.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ namespace BenchmarkDotNet.Running
1818
public static class BenchmarkRunner
1919
{
2020
[PublicAPI]
21-
public static Summary Run<T>(IConfig config = null, string[] args = null)
21+
public static Summary Run<T>(IConfig? config = null, string[]? args = null)
2222
{
2323
using (DirtyAssemblyResolveHelper.Create())
2424
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(typeof(T), config, args));
2525
}
2626

2727
[PublicAPI]
28-
public static Summary Run(Type type, IConfig config = null, string[] args = null)
28+
public static Summary Run(Type type, IConfig? config = null, string[]? args = null)
2929
{
3030
using (DirtyAssemblyResolveHelper.Create())
3131
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(type, config, args));
3232
}
3333

3434
[PublicAPI]
35-
public static Summary[] Run(Type[] types, IConfig config = null, string[] args = null)
35+
public static Summary[] Run(Type[] types, IConfig? config = null, string[]? args = null)
3636
{
3737
using (DirtyAssemblyResolveHelper.Create())
3838
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(types, config, args));
3939
}
4040

4141
[PublicAPI]
42-
public static Summary Run(Type type, MethodInfo[] methods, IConfig config = null)
42+
public static Summary Run(Type type, MethodInfo[] methods, IConfig? config = null)
4343
{
4444
using (DirtyAssemblyResolveHelper.Create())
4545
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(type, methods, config));
4646
}
4747

4848
[PublicAPI]
49-
public static Summary[] Run(Assembly assembly, IConfig config = null, string[] args = null)
49+
public static Summary[] Run(Assembly assembly, IConfig? config = null, string[]? args = null)
5050
{
5151
using (DirtyAssemblyResolveHelper.Create())
5252
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(assembly, config, args));
@@ -69,7 +69,7 @@ public static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
6969
[PublicAPI]
7070
[EditorBrowsable(EditorBrowsableState.Never)]
7171
[Obsolete("This method will be removed soon as it is not supported in .NET Core")]
72-
public static Summary RunUrl(string url, IConfig config = null)
72+
public static Summary RunUrl(string url, IConfig? config = null)
7373
{
7474
using (DirtyAssemblyResolveHelper.Create())
7575
return RunWithExceptionHandling(() => RunUrlWithDirtyAssemblyResolveHelper(url, config));
@@ -78,31 +78,31 @@ public static Summary RunUrl(string url, IConfig config = null)
7878
[PublicAPI]
7979
[EditorBrowsable(EditorBrowsableState.Never)]
8080
[Obsolete("This method will be removed soon as it is not supported in .NET Core")]
81-
public static Summary RunSource(string source, IConfig config = null)
81+
public static Summary RunSource(string source, IConfig? config = null)
8282
{
8383
using (DirtyAssemblyResolveHelper.Create())
8484
return RunWithExceptionHandling(() => RunSourceWithDirtyAssemblyResolveHelper(source, config));
8585
}
8686

8787
[MethodImpl(MethodImplOptions.NoInlining)]
88-
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, IConfig config, string[] args)
88+
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, IConfig? config, string[]? args)
8989
=> (args == null
9090
? BenchmarkRunnerClean.Run(new[] { BenchmarkConverter.TypeToBenchmarks(type, config) })
9191
: new BenchmarkSwitcher(new[] { type }).RunWithDirtyAssemblyResolveHelper(args, config, false))
9292
.Single();
9393

9494
[MethodImpl(MethodImplOptions.NoInlining)]
95-
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, MethodInfo[] methods, IConfig config = null)
95+
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, MethodInfo[] methods, IConfig? config = null)
9696
=> BenchmarkRunnerClean.Run(new[] { BenchmarkConverter.MethodsToBenchmarks(type, methods, config) }).Single();
9797

9898
[MethodImpl(MethodImplOptions.NoInlining)]
99-
private static Summary[] RunWithDirtyAssemblyResolveHelper(Assembly assembly, IConfig config, string[] args)
99+
private static Summary[] RunWithDirtyAssemblyResolveHelper(Assembly assembly, IConfig? config, string[]? args)
100100
=> args == null
101101
? BenchmarkRunnerClean.Run(assembly.GetRunnableBenchmarks().Select(type => BenchmarkConverter.TypeToBenchmarks(type, config)).ToArray())
102102
: new BenchmarkSwitcher(assembly).RunWithDirtyAssemblyResolveHelper(args, config, false).ToArray();
103103

104104
[MethodImpl(MethodImplOptions.NoInlining)]
105-
private static Summary[] RunWithDirtyAssemblyResolveHelper(Type[] types, IConfig config, string[] args)
105+
private static Summary[] RunWithDirtyAssemblyResolveHelper(Type[] types, IConfig? config, string[]? args)
106106
=> args == null
107107
? BenchmarkRunnerClean.Run(types.Select(type => BenchmarkConverter.TypeToBenchmarks(type, config)).ToArray())
108108
: new BenchmarkSwitcher(types).RunWithDirtyAssemblyResolveHelper(args, config, false).ToArray();
@@ -113,13 +113,13 @@ private static Summary[] RunWithDirtyAssemblyResolveHelper(BenchmarkRunInfo[] be
113113

114114
#pragma warning disable CS0618 // Use of obsolete symbol
115115
[MethodImpl(MethodImplOptions.NoInlining)]
116-
private static Summary RunUrlWithDirtyAssemblyResolveHelper(string url, IConfig config = null)
116+
private static Summary RunUrlWithDirtyAssemblyResolveHelper(string url, IConfig? config = null)
117117
=> RuntimeInformation.IsFullFramework
118118
? BenchmarkRunnerClean.Run(BenchmarkConverter.UrlToBenchmarks(url, config)).Single()
119119
: throw new InvalidBenchmarkDeclarationException("Supported only on Full .NET Framework");
120120

121121
[MethodImpl(MethodImplOptions.NoInlining)]
122-
private static Summary RunSourceWithDirtyAssemblyResolveHelper(string source, IConfig config = null)
122+
private static Summary RunSourceWithDirtyAssemblyResolveHelper(string source, IConfig? config = null)
123123
=> RuntimeInformation.IsFullFramework
124124
? BenchmarkRunnerClean.Run(BenchmarkConverter.SourceToBenchmarks(source, config)).Single()
125125
: throw new InvalidBenchmarkDeclarationException("Supported only on Full .NET Framework");

src/BenchmarkDotNet/Running/BenchmarkSwitcher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public class BenchmarkSwitcher
5353
/// <summary>
5454
/// Run all available benchmarks.
5555
/// </summary>
56-
[PublicAPI] public IEnumerable<Summary> RunAll(IConfig config = null) => Run(new[] { "--filter", "*" }, config);
56+
[PublicAPI] public IEnumerable<Summary> RunAll(IConfig? config = null) => Run(new[] { "--filter", "*" }, config);
5757

5858
/// <summary>
5959
/// Run all available benchmarks and join them to a single summary
6060
/// </summary>
61-
[PublicAPI] public Summary RunAllJoined(IConfig config = null) => Run(new[] { "--filter", "*", "--join" }, config).Single();
61+
[PublicAPI] public Summary RunAllJoined(IConfig? config = null) => Run(new[] { "--filter", "*", "--join" }, config).Single();
6262

6363
[PublicAPI]
64-
public IEnumerable<Summary> Run(string[] args = null, IConfig config = null)
64+
public IEnumerable<Summary> Run(string[]? args = null, IConfig? config = null)
6565
{
6666
// VS generates bad assembly binding redirects for ValueTuple for Full .NET Framework
6767
// we need to keep the logic that uses it in a separate method and create DirtyAssemblyResolveHelper first
@@ -71,7 +71,7 @@ public IEnumerable<Summary> Run(string[] args = null, IConfig config = null)
7171
}
7272

7373
[MethodImpl(MethodImplOptions.NoInlining)]
74-
internal IEnumerable<Summary> RunWithDirtyAssemblyResolveHelper(string[] args, IConfig config, bool askUserForInput)
74+
internal IEnumerable<Summary> RunWithDirtyAssemblyResolveHelper(string[]? args, IConfig? config, bool askUserForInput)
7575
{
7676
var notNullArgs = args ?? Array.Empty<string>();
7777
var notNullConfig = config ?? DefaultConfig.Instance;

src/BenchmarkDotNet/Running/ClassicBenchmarkConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static partial class BenchmarkConverter
2525

2626
[EditorBrowsable(EditorBrowsableState.Never)]
2727
[Obsolete("This method will be removed soon as it is not supported in .NET Core")]
28-
public static BenchmarkRunInfo[] UrlToBenchmarks(string url, IConfig config = null)
28+
public static BenchmarkRunInfo[] UrlToBenchmarks(string url, IConfig? config = null)
2929
{
3030
if (!RuntimeInformation.IsFullFramework)
3131
throw new NotSupportedException("Supported only on Full .NET Framework.");
@@ -70,7 +70,7 @@ public static BenchmarkRunInfo[] UrlToBenchmarks(string url, IConfig config = nu
7070

7171
[EditorBrowsable(EditorBrowsableState.Never)]
7272
[Obsolete("This method will be removed soon as it is not supported in .NET Core")]
73-
public static BenchmarkRunInfo[] SourceToBenchmarks(string source, IConfig config = null)
73+
public static BenchmarkRunInfo[] SourceToBenchmarks(string source, IConfig? config = null)
7474
{
7575
if (!RuntimeInformation.IsFullFramework)
7676
throw new NotSupportedException("Supported only on Full .NET Framework.");

0 commit comments

Comments
 (0)