diff --git a/CliWrap.Benchmarks/PipeFromStreamBenchmarks.cs b/CliWrap.Benchmarks/PipeFromStreamBenchmarks.cs index b3584e40..ff2cec84 100644 --- a/CliWrap.Benchmarks/PipeFromStreamBenchmarks.cs +++ b/CliWrap.Benchmarks/PipeFromStreamBenchmarks.cs @@ -14,7 +14,7 @@ public class PipeFromStreamBenchmarks [Benchmark(Baseline = true)] public async Task ExecuteWithCliWrap_PipeToStream() { - await using var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 }); + await using var stream = new MemoryStream([1, 2, 3, 4, 5]); var command = stream | Cli.Wrap(FilePath).WithArguments(Args); await command.ExecuteAsync(); @@ -25,7 +25,7 @@ public async Task ExecuteWithCliWrap_PipeToStream() [Benchmark] public async Task MedallionShell() { - await using var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 }); + await using var stream = new MemoryStream([1, 2, 3, 4, 5]); var command = Medallion.Shell.Command.Run(FilePath, Args.Split(' ')) < stream; await command.Task; diff --git a/CliWrap.Tests.Dummy/CliWrap.Tests.Dummy.csproj b/CliWrap.Tests.Dummy/CliWrap.Tests.Dummy.csproj index c6e2c6c9..14bcd64c 100644 --- a/CliWrap.Tests.Dummy/CliWrap.Tests.Dummy.csproj +++ b/CliWrap.Tests.Dummy/CliWrap.Tests.Dummy.csproj @@ -9,7 +9,7 @@ - + diff --git a/CliWrap.Tests.Dummy/Commands/EnvironmentCommand.cs b/CliWrap.Tests.Dummy/Commands/EnvironmentCommand.cs index 5fef363c..2acb8215 100644 --- a/CliWrap.Tests.Dummy/Commands/EnvironmentCommand.cs +++ b/CliWrap.Tests.Dummy/Commands/EnvironmentCommand.cs @@ -11,7 +11,7 @@ namespace CliWrap.Tests.Dummy.Commands; public class EnvironmentCommand : ICommand { [CommandParameter(0)] - public IReadOnlyList Names { get; init; } = Array.Empty(); + public IReadOnlyList Names { get; init; } = []; public async ValueTask ExecuteAsync(IConsole console) { diff --git a/CliWrap.Tests.Dummy/Commands/Shared/OutputTarget.cs b/CliWrap.Tests.Dummy/Commands/Shared/OutputTarget.cs index 47dfe65b..cae574f8 100644 --- a/CliWrap.Tests.Dummy/Commands/Shared/OutputTarget.cs +++ b/CliWrap.Tests.Dummy/Commands/Shared/OutputTarget.cs @@ -9,7 +9,7 @@ public enum OutputTarget { StdOut = 1, StdErr = 2, - All = StdOut | StdErr + All = StdOut | StdErr, } internal static class OutputTargetExtensions diff --git a/CliWrap.Tests/CliWrap.Tests.csproj b/CliWrap.Tests/CliWrap.Tests.csproj index d44ea46b..7d9ccafd 100644 --- a/CliWrap.Tests/CliWrap.Tests.csproj +++ b/CliWrap.Tests/CliWrap.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/CliWrap.Tests/ConfigurationSpecs.cs b/CliWrap.Tests/ConfigurationSpecs.cs index 554b038f..a02db08a 100644 --- a/CliWrap.Tests/ConfigurationSpecs.cs +++ b/CliWrap.Tests/ConfigurationSpecs.cs @@ -192,7 +192,7 @@ public void I_can_configure_the_environment_variables_using_a_builder() ["name"] = "value", ["key"] = "door", ["zzz"] = "yyy", - ["aaa"] = "bbb" + ["aaa"] = "bbb", } ); } diff --git a/CliWrap.Tests/PipingSpecs.cs b/CliWrap.Tests/PipingSpecs.cs index 66d84f5e..0f39dd48 100644 --- a/CliWrap.Tests/PipingSpecs.cs +++ b/CliWrap.Tests/PipingSpecs.cs @@ -540,7 +540,7 @@ public async Task I_can_execute_a_command_and_pipe_the_stdout_into_multiple_stre "1000000", // Buffer needs to be >= BufferSizes.Stream to fail "--buffer", - "100000" + "100000", ] ); diff --git a/CliWrap/CliWrap.csproj b/CliWrap/CliWrap.csproj index 96a5ec60..94cde987 100644 --- a/CliWrap/CliWrap.csproj +++ b/CliWrap/CliWrap.csproj @@ -26,7 +26,7 @@ - + diff --git a/CliWrap/Command.Execution.cs b/CliWrap/Command.Execution.cs index 5fed29d1..35e31930 100644 --- a/CliWrap/Command.Execution.cs +++ b/CliWrap/Command.Execution.cs @@ -23,7 +23,9 @@ private string GetOptimallyQualifiedTargetFilePath() // Currently, we only need this workaround for script files on Windows, so short-circuit // if we are on a different platform. if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { return TargetFilePath; + } // Don't do anything for fully qualified paths or paths that already have an extension specified. // System.Diagnostics.Process knows how to handle those without our help. @@ -34,7 +36,9 @@ private string GetOptimallyQualifiedTargetFilePath() Path.IsPathRooted(TargetFilePath) || !string.IsNullOrWhiteSpace(Path.GetExtension(TargetFilePath)) ) + { return TargetFilePath; + } static IEnumerable GetProbeDirectoryPaths() { @@ -86,7 +90,7 @@ private ProcessStartInfo CreateStartInfo() // We need this in order to be able to send signals to one specific child process, // without affecting any others that may also be running in parallel. // https://github.com/Tyrrrz/CliWrap/issues/47 - CreateNoWindow = true + CreateNoWindow = true, }; // Set credentials diff --git a/CliWrap/CommandResultValidation.cs b/CliWrap/CommandResultValidation.cs index 4034166b..881bc665 100644 --- a/CliWrap/CommandResultValidation.cs +++ b/CliWrap/CommandResultValidation.cs @@ -16,7 +16,7 @@ public enum CommandResultValidation /// /// Ensure that the command returned a zero exit code. /// - ZeroExitCode = 0b1 + ZeroExitCode = 0b1, } internal static class CommandResultValidationExtensions diff --git a/CliWrap/Utils/Observable.cs b/CliWrap/Utils/Observable.cs index 947c329a..4aadc8bb 100644 --- a/CliWrap/Utils/Observable.cs +++ b/CliWrap/Utils/Observable.cs @@ -12,8 +12,6 @@ internal static class Observable public static IObservable Create(Func, IDisposable> subscribe) => new Observable(subscribe); - public static IObservable CreateSynchronized( - Func, IDisposable> subscribe, - object? syncRoot = null - ) => Create(observer => subscribe(new SynchronizedObserver(observer, syncRoot))); + public static IObservable CreateSynchronized(Func, IDisposable> subscribe) => + Create(observer => subscribe(new SynchronizedObserver(observer))); } diff --git a/CliWrap/Utils/SimplexStream.cs b/CliWrap/Utils/SimplexStream.cs index 4adb6c0b..4aefeb35 100644 --- a/CliWrap/Utils/SimplexStream.cs +++ b/CliWrap/Utils/SimplexStream.cs @@ -90,7 +90,7 @@ CancellationToken cancellationToken public async Task ReportCompletionAsync(CancellationToken cancellationToken = default) => // Write an empty buffer that will make ReadAsync(...) return 0, which signifies the end of stream - await WriteAsync(Array.Empty(), 0, 0, cancellationToken).ConfigureAwait(false); + await WriteAsync([], 0, 0, cancellationToken).ConfigureAwait(false); protected override void Dispose(bool disposing) { diff --git a/CliWrap/Utils/SynchronizedObserver.cs b/CliWrap/Utils/SynchronizedObserver.cs index 822e1318..24e95fc1 100644 --- a/CliWrap/Utils/SynchronizedObserver.cs +++ b/CliWrap/Utils/SynchronizedObserver.cs @@ -1,15 +1,15 @@ using System; +using System.Threading; namespace CliWrap.Utils; -internal class SynchronizedObserver(IObserver observer, object? syncRoot = null) - : IObserver +internal class SynchronizedObserver(IObserver observer) : IObserver { - private readonly object _syncRoot = syncRoot ?? new object(); + private readonly Lock _lock = new(); public void OnCompleted() { - lock (_syncRoot) + using (_lock.EnterScope()) { observer.OnCompleted(); } @@ -17,7 +17,7 @@ public void OnCompleted() public void OnError(Exception error) { - lock (_syncRoot) + using (_lock.EnterScope()) { observer.OnError(error); } @@ -25,7 +25,7 @@ public void OnError(Exception error) public void OnNext(T value) { - lock (_syncRoot) + using (_lock.EnterScope()) { observer.OnNext(value); } diff --git a/CliWrap/Utils/WindowsSignaler.cs b/CliWrap/Utils/WindowsSignaler.cs index 887c623a..891b44e1 100644 --- a/CliWrap/Utils/WindowsSignaler.cs +++ b/CliWrap/Utils/WindowsSignaler.cs @@ -27,9 +27,9 @@ public bool TrySend(int processId, int signalId) // This is a .NET 3.5 executable, so we need to configure framework rollover // to allow it to also run against .NET 4.0 and higher. // https://gist.github.com/MichalStrehovsky/d6bc5e4d459c23d0cf3bd17af9a1bcf5 - ["COMPLUS_OnlyUseLatestCLR"] = "1" - } - } + ["COMPLUS_OnlyUseLatestCLR"] = "1", + }, + }, }; if (!process.Start())