diff --git a/src/Spectre.Console.Cli/Internal/Binding/CommandValueResolver.cs b/src/Spectre.Console.Cli/Internal/Binding/CommandValueResolver.cs
index 6812c7a..d2d5334 100644
--- a/src/Spectre.Console.Cli/Internal/Binding/CommandValueResolver.cs
+++ b/src/Spectre.Console.Cli/Internal/Binding/CommandValueResolver.cs
@@ -85,7 +85,7 @@ internal static class CommandValueResolver
}
// Assign the value to the parameter.
- binder.Bind(mapped.Parameter, resolver, converter.ConvertFromInvariantString(mapped.Value));
+ binder.Bind(mapped.Parameter, resolver, converter.ConvertFromInvariantString(mapped.Value ?? string.Empty));
}
}
@@ -130,7 +130,13 @@ internal static class CommandValueResolver
if (parameter.ParameterType.IsArray)
{
// Return a converter for each array item (not the whole array)
- return TypeDescriptor.GetConverter(parameter.ParameterType.GetElementType());
+ var elementType = parameter.ParameterType.GetElementType();
+ if (elementType == null)
+ {
+ throw new InvalidOperationException("Could not get element type");
+ }
+
+ return TypeDescriptor.GetConverter(elementType);
}
if (parameter.IsFlagValue())
diff --git a/src/Spectre.Console.Cli/Internal/HelpWriter.cs b/src/Spectre.Console.Cli/Internal/HelpWriter.cs
index 8d6dcfa..d6b0b38 100644
--- a/src/Spectre.Console.Cli/Internal/HelpWriter.cs
+++ b/src/Spectre.Console.Cli/Internal/HelpWriter.cs
@@ -29,13 +29,13 @@ internal static class HelpWriter
private sealed class HelpOption
{
- public string Short { get; }
- public string Long { get; }
+ public string? Short { get; }
+ public string? Long { get; }
public string? Value { get; }
public bool? ValueIsOptional { get; }
public string? Description { get; }
- public HelpOption(string @short, string @long, string? @value, bool? valueIsOptional, string? description)
+ public HelpOption(string? @short, string? @long, string? @value, bool? valueIsOptional, string? description)
{
Short = @short;
Long = @long;
diff --git a/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj b/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj
index 99623d2..658dd16 100644
--- a/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj
+++ b/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj
@@ -17,7 +17,12 @@
-
+
+ 3.0.0
+ False
+
+
+
@@ -26,9 +31,4 @@
-
- 3.0.0
- False
-
-
diff --git a/src/Spectre.Console/Internal/TypeConverterHelper.cs b/src/Spectre.Console/Internal/TypeConverterHelper.cs
index 901b308..03c393e 100644
--- a/src/Spectre.Console/Internal/TypeConverterHelper.cs
+++ b/src/Spectre.Console/Internal/TypeConverterHelper.cs
@@ -4,14 +4,20 @@ internal static class TypeConverterHelper
{
public static string ConvertToString(T input)
{
- return GetTypeConverter().ConvertToInvariantString(input);
+ var result = GetTypeConverter().ConvertToInvariantString(input);
+ if (result == null)
+ {
+ throw new InvalidOperationException("Could not convert input to a string");
+ }
+
+ return result;
}
- public static bool TryConvertFromString(string input, [MaybeNull] out T result)
+ public static bool TryConvertFromString(string input, [MaybeNull] out T? result)
{
try
{
- result = (T)GetTypeConverter().ConvertFromInvariantString(input);
+ result = (T?)GetTypeConverter().ConvertFromInvariantString(input);
return true;
}
catch
@@ -21,7 +27,7 @@ internal static class TypeConverterHelper
}
}
- public static bool TryConvertFromStringWithCulture(string input, CultureInfo? info, [MaybeNull] out T result)
+ public static bool TryConvertFromStringWithCulture(string input, CultureInfo? info, [MaybeNull] out T? result)
{
try
{
@@ -31,7 +37,7 @@ internal static class TypeConverterHelper
}
else
{
- result = (T)GetTypeConverter().ConvertFromString(null!, info, input);
+ result = (T?)GetTypeConverter().ConvertFromString(null!, info, input);
}
return true;
diff --git a/src/Spectre.Console/Spectre.Console.csproj b/src/Spectre.Console/Spectre.Console.csproj
index d3ec1c9..102ef07 100644
--- a/src/Spectre.Console/Spectre.Console.csproj
+++ b/src/Spectre.Console/Spectre.Console.csproj
@@ -17,22 +17,25 @@
+
+ all
+
+
+
+
+ 3.0.0
+ False
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
- all
-
-
- 3.0.0
- False
-
-
$(DefineConstants)TRACE;WCWIDTH_VISIBILITY_INTERNAL
diff --git a/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs b/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs
index 0ec352b..fc03993 100644
--- a/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs
+++ b/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs
@@ -5,14 +5,20 @@ internal static class FigletFontParser
public static FigletFont Parse(string source)
{
var lines = source.SplitLines();
- var header = ParseHeader(lines.FirstOrDefault());
- var characters = new List();
+ var headerLine = lines.FirstOrDefault();
+ if (headerLine == null)
+ {
+ throw new InvalidOperationException("Could not read header line");
+ }
+
+ var header = ParseHeader(headerLine);
var index = 32;
var indexOverridden = false;
var hasOverriddenIndex = false;
var buffer = new List();
+ var characters = new List();
foreach (var line in lines.Skip(header.CommentLines + 1))
{
diff --git a/src/Spectre.Console/Widgets/Table/TableRowCollection.cs b/src/Spectre.Console/Widgets/Table/TableRowCollection.cs
index 11c0938..6510c81 100644
--- a/src/Spectre.Console/Widgets/Table/TableRowCollection.cs
+++ b/src/Spectre.Console/Widgets/Table/TableRowCollection.cs
@@ -107,8 +107,7 @@ public sealed class TableRowCollection : IReadOnlyList
throw new IndexOutOfRangeException("Table row index cannot exceed the number of rows in the table.");
}
- var tableRow = _list.ElementAtOrDefault(row);
-
+ var tableRow = _list.ElementAt(row);
var currentRenderables = tableRow.ToList();
if (column < 0)