From 5b1d19f293bda96b513e4a5af2dcaba3713ec6b4 Mon Sep 17 00:00:00 2001 From: Thomas Levesque Date: Sun, 31 Dec 2023 15:46:37 -0500 Subject: [PATCH] Fix CommandArgumentEnumerator behavior for .NET 8 --- src/CommandLineUtils/Internal/CommandLineProcessor.cs | 7 +++++-- .../McMaster.Extensions.CommandLineUtils.Tests.csproj | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/CommandLineUtils/Internal/CommandLineProcessor.cs b/src/CommandLineUtils/Internal/CommandLineProcessor.cs index 5a515784..cc9c248c 100644 --- a/src/CommandLineUtils/Internal/CommandLineProcessor.cs +++ b/src/CommandLineUtils/Internal/CommandLineProcessor.cs @@ -525,7 +525,7 @@ public CommandArgumentEnumerator(IEnumerator enumerator) _enumerator = enumerator; } - public CommandArgument Current => _enumerator.Current; + public CommandArgument Current { get; private set; } = null!; object IEnumerator.Current => Current; @@ -535,7 +535,10 @@ public bool MoveNext() { if (Current == null || !Current.MultipleValues) { - return _enumerator.MoveNext(); + var result = _enumerator.MoveNext(); + if (result) + Current = _enumerator.Current!; + return result; } // 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