diff --git a/src/CLIParser/CLIParser.cs b/src/CLIParser/CLIParser.cs index 0262fe9..923bf81 100644 --- a/src/CLIParser/CLIParser.cs +++ b/src/CLIParser/CLIParser.cs @@ -76,19 +76,22 @@ public static string ToString(this IEnumerable metadatas, str /// The string equivalent for command-line public static string ToString(this IArgumentMetadata metadata, params object[] values) { - if (metadata.Type != ArgumentType.Single && values == null || values.Length == 0) throw new ArgumentException("Cannot be null or empty", "values"); string valueStr = string.Empty; - if (metadata.IsMultiValue) + if (metadata.Type != ArgumentType.Single) { - foreach (var item in values) + if (values == null || values.Length == 0) throw new ArgumentException("Cannot be null or empty", "values"); + if (metadata.IsMultiValue) { - valueStr += $"{item}{metadata.MultiValueSeparator}"; + foreach (var item in values) + { + valueStr += $"{item}{metadata.MultiValueSeparator}"; + } + valueStr = valueStr.Substring(0, valueStr.Length - 1); + } + else + { + valueStr = values[0].ToString(); } - valueStr = valueStr.Substring(0, valueStr.Length - 1); - } - else - { - valueStr = values[0].ToString(); } var prefix = metadata.PrefixInUse; diff --git a/src/CLIParser/CLIParser.csproj b/src/CLIParser/CLIParser.csproj index 7918460..6d337fa 100644 --- a/src/CLIParser/CLIParser.csproj +++ b/src/CLIParser/CLIParser.csproj @@ -8,7 +8,7 @@ MASES s.r.l. MASES s.r.l. MASES s.r.l. - 3.1.1.0 + 3.1.2.0 CLIParser true netstandard2.0 diff --git a/tests/CLIParserTest/CLIParserTest.csproj b/tests/CLIParserTest/CLIParserTest.csproj index 85e4298..0220ebc 100644 --- a/tests/CLIParserTest/CLIParserTest.csproj +++ b/tests/CLIParserTest/CLIParserTest.csproj @@ -9,7 +9,7 @@ Copyright © MASES s.r.l. 2022 MASES s.r.l. MASES s.r.l. - 3.1.1.0 + 3.1.2.0 net461;netcoreapp3.1;net5.0;net6.0 ..\..\bin\ diff --git a/tests/CLIParserTest/Program.cs b/tests/CLIParserTest/Program.cs index 63fa378..ed4f438 100644 --- a/tests/CLIParserTest/Program.cs +++ b/tests/CLIParserTest/Program.cs @@ -102,6 +102,9 @@ static void Main(string[] args) var result = parser.Parse(args); + var resultToString = parser.Arguments.ToString("MyParam2", "TEST"); + resultToString = parser.Arguments.ToString("myval"); + var fileInfo = parser.FromFile(result); parser.Override(result, fileInfo);