Fix issues with nullability and netstandard2.0

This commit is contained in:
Patrik Svensson
2022-11-10 10:21:05 +01:00
committed by Patrik Svensson
parent 7dce4af552
commit a70cc90797
7 changed files with 48 additions and 28 deletions

View File

@ -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())

View File

@ -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;