diff --git a/src/CommandLineUtils/Internal/CommandLineProcessor.cs b/src/CommandLineUtils/Internal/CommandLineProcessor.cs index 5a515784..4efa9701 100644 --- a/src/CommandLineUtils/Internal/CommandLineProcessor.cs +++ b/src/CommandLineUtils/Internal/CommandLineProcessor.cs @@ -519,10 +519,12 @@ public void Dispose() private sealed class CommandArgumentEnumerator : IEnumerator { private readonly IEnumerator _enumerator; + private bool _currentValid; public CommandArgumentEnumerator(IEnumerator enumerator) { _enumerator = enumerator; + _currentValid = false; } public CommandArgument Current => _enumerator.Current; @@ -533,9 +535,10 @@ public CommandArgumentEnumerator(IEnumerator enumerator) public bool MoveNext() { - if (Current == null || !Current.MultipleValues) + if (!_currentValid || !Current.MultipleValues) { - return _enumerator.MoveNext(); + _currentValid = _enumerator.MoveNext(); + return _currentValid; } // If current argument allows multiple values, we don't move forward and diff --git a/test/CommandLineUtils.Tests/McMaster.Extensions.CommandLineUtils.Tests.csproj b/test/CommandLineUtils.Tests/McMaster.Extensions.CommandLineUtils.Tests.csproj index 86a48b14..a04e46db 100644 --- a/test/CommandLineUtils.Tests/McMaster.Extensions.CommandLineUtils.Tests.csproj +++ b/test/CommandLineUtils.Tests/McMaster.Extensions.CommandLineUtils.Tests.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 $(TargetFrameworks);net472 annotations diff --git a/test/Hosting.CommandLine.Tests/McMaster.Extensions.Hosting.CommandLine.Tests.csproj b/test/Hosting.CommandLine.Tests/McMaster.Extensions.Hosting.CommandLine.Tests.csproj index b1820d12..8760e52a 100644 --- a/test/Hosting.CommandLine.Tests/McMaster.Extensions.Hosting.CommandLine.Tests.csproj +++ b/test/Hosting.CommandLine.Tests/McMaster.Extensions.Hosting.CommandLine.Tests.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 $(TargetFrameworks);net472