From 1543076bf40a2a783cc1f9474862698f2dd50b36 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Sun, 9 Jun 2019 22:14:01 +0300 Subject: [PATCH] Throw exception when an option has multiple values but the target type is not an array --- CliFx/Services/CommandOptionConverter.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CliFx/Services/CommandOptionConverter.cs b/CliFx/Services/CommandOptionConverter.cs index 6860487..861fe05 100644 --- a/CliFx/Services/CommandOptionConverter.cs +++ b/CliFx/Services/CommandOptionConverter.cs @@ -228,13 +228,19 @@ namespace CliFx.Services throw new CommandOptionConvertException( $"Can't convert sequence of values [{option.Values.JoinToString(", ")}] to type [{targetType}]."); } - else + else if (option.Values.Count <= 1) { // Take first value and ignore the rest - var value = option.Values.FirstOrDefault(); + var value = option.Values.SingleOrDefault(); return ConvertValue(value, targetType); } + else + { + // TODO: better exception + throw new CommandOptionConvertException( + $"Can't convert sequence of values [{option.Values.JoinToString(", ")}] to type [{targetType}]."); + } } } } \ No newline at end of file