Skip to content

Commit

Permalink
Add StringExtensions.EqualsIgnoreCase
Browse files Browse the repository at this point in the history
  • Loading branch information
si618 committed Mar 20, 2024
1 parent 912f9f2 commit 68a3cbb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Benchmarks.App/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static IEnumerable<Summary> RunAndBuildSummaries()
public static IEnumerable<Summary> RunAndBuildSummaries(BenchmarkSettings settings)
{
var args = settings.BuildArgs();
var type = Reflection.GetBenchmarkTypes().First(type => type.Name == settings.Name);
var type = Reflection.GetBenchmarkTypes()
.First(type => type.Name.EqualsIgnoreCase(settings.Name));

return RunAndBuildSummaries([type], args);
}
Expand Down
3 changes: 1 addition & 2 deletions Benchmarks.App/Commands/BenchmarkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public override ValidationResult Validate()
return ValidationResult.Error("Benchmark name required");
}

if (Reflection.GetBenchmarkTypes()
.All(type => !type.Name.Equals(Name, StringComparison.InvariantCultureIgnoreCase)))
if (Reflection.GetBenchmarkTypes().All(type => !type.Name.EqualsIgnoreCase(Name)))
{
return ValidationResult.Error($"Benchmark not found '{Name}'");
}
Expand Down
2 changes: 2 additions & 0 deletions Benchmarks.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
global using Benchmarks.App.Commands;
global using Benchmarks.App.Menus;
global using Benchmarks.App.Menus.Selections;
global using Benchmarks.Core;
global using Benchmarks.Core.Benchmarking;
global using DotNet.Testcontainers.Builders;
global using Lolcat;
global using Spectre.Console;
global using Spectre.Console.Cli;
global using Spectre.Console.Rendering;
global using System;
global using System.ComponentModel;
global using System.Reflection;
global using System.Text;
Expand Down
5 changes: 2 additions & 3 deletions Benchmarks.App/PreFlightCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ internal static class PreFlightCheck

internal static bool IsNeeded(string[] args) =>
args.Length > 0 && // Not needed when showing app details
args.All(arg => !arg.StartsWith('-')) && // Not needed for help or version options
args.Any(arg => NeedsPreFlightCheck // Not needed for info or list commands
.Any(pf => arg.Equals(pf, StringComparison.OrdinalIgnoreCase)));
args.All(arg => !arg.StartsWith('-')) && // or for --help or --version options
args.Any(arg => NeedsPreFlightCheck.Any(arg.EqualsIgnoreCase));

internal static void Run(IEnumerable<string> args)
{
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks.App/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public static bool TryGetBenchmark(string name, out Benchmark benchmark)
var found = GetBenchmarkTypes()
.Select(GetBenchmark)
.FirstOrDefault(b =>
b.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) ||
b.Description.Equals(name, StringComparison.InvariantCultureIgnoreCase));
b.Name.EqualsIgnoreCase(name) ||
b.Description.EqualsIgnoreCase(name));

benchmark = found ?? null!;

Expand Down
7 changes: 7 additions & 0 deletions Benchmarks.Core/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Benchmarks.Core;

public static class StringExtensions
{
public static bool EqualsIgnoreCase(this string value, string? other) =>
string.Equals(value, other, StringComparison.InvariantCultureIgnoreCase);
}

0 comments on commit 68a3cbb

Please sign in to comment.