mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-24 02:25:48 +08:00
Fix issues with nullability and netstandard2.0
This commit is contained in:
committed by
Patrik Svensson
parent
7dce4af552
commit
a70cc90797
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user