mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-14 16:02:50 +08:00
Fix issues with nullability and netstandard2.0
This commit is contained in:
parent
7dce4af552
commit
a70cc90797
@ -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())
|
||||
|
@ -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;
|
||||
|
@ -17,7 +17,12 @@
|
||||
<InternalsVisibleTo Include="Spectre.Console.Cli.Tests" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<AnnotatedReferenceAssemblyVersion>3.0.0</AnnotatedReferenceAssemblyVersion>
|
||||
<GenerateNullableAttributes>False</GenerateNullableAttributes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
|
||||
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
|
||||
<PackageReference Include="Nullable" Version="1.3.1">
|
||||
@ -26,9 +31,4 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<AnnotatedReferenceAssemblyVersion>3.0.0</AnnotatedReferenceAssemblyVersion>
|
||||
<GenerateNullableAttributes>False</GenerateNullableAttributes>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -4,14 +4,20 @@ internal static class TypeConverterHelper
|
||||
{
|
||||
public static string ConvertToString<T>(T input)
|
||||
{
|
||||
return GetTypeConverter<T>().ConvertToInvariantString(input);
|
||||
var result = GetTypeConverter<T>().ConvertToInvariantString(input);
|
||||
if (result == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not convert input to a string");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool TryConvertFromString<T>(string input, [MaybeNull] out T result)
|
||||
public static bool TryConvertFromString<T>(string input, [MaybeNull] out T? result)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = (T)GetTypeConverter<T>().ConvertFromInvariantString(input);
|
||||
result = (T?)GetTypeConverter<T>().ConvertFromInvariantString(input);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
@ -21,7 +27,7 @@ internal static class TypeConverterHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryConvertFromStringWithCulture<T>(string input, CultureInfo? info, [MaybeNull] out T result)
|
||||
public static bool TryConvertFromStringWithCulture<T>(string input, CultureInfo? info, [MaybeNull] out T? result)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -31,7 +37,7 @@ internal static class TypeConverterHelper
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (T)GetTypeConverter<T>().ConvertFromString(null!, info, input);
|
||||
result = (T?)GetTypeConverter<T>().ConvertFromString(null!, info, input);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -17,22 +17,25 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Memory" Version="4.5.5" />
|
||||
<PackageReference Include="Wcwidth.Sources" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<AnnotatedReferenceAssemblyVersion>3.0.0</AnnotatedReferenceAssemblyVersion>
|
||||
<GenerateNullableAttributes>False</GenerateNullableAttributes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
|
||||
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
|
||||
<PackageReference Include="Nullable" Version="1.3.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Wcwidth.Sources" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<AnnotatedReferenceAssemblyVersion>3.0.0</AnnotatedReferenceAssemblyVersion>
|
||||
<GenerateNullableAttributes>False</GenerateNullableAttributes>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefineConstants>$(DefineConstants)TRACE;WCWIDTH_VISIBILITY_INTERNAL</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
@ -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<FigletCharacter>();
|
||||
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<string>();
|
||||
var characters = new List<FigletCharacter>();
|
||||
|
||||
foreach (var line in lines.Skip(header.CommentLines + 1))
|
||||
{
|
||||
|
@ -107,8 +107,7 @@ public sealed class TableRowCollection : IReadOnlyList<TableRow>
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user