mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-24 02:25:48 +08:00
Add culture option to TypeConverterHelper, TextPrompt and AnsiConsole (#1014)
* Add culture option to TypeConverterHelper, TextPrompt and AnsiConsole * Add IHasCulture interface
This commit is contained in:
@@ -21,6 +21,28 @@ internal static class TypeConverterHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryConvertFromStringWithCulture<T>(string input, CultureInfo? info, [MaybeNull] out T result)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (info == null)
|
||||
{
|
||||
return TryConvertFromString<T>(input, out result);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (T)GetTypeConverter<T>().ConvertFromString(null!, info, input);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static TypeConverter GetTypeConverter<T>()
|
||||
{
|
||||
var converter = TypeDescriptor.GetConverter(typeof(T));
|
||||
|
||||
Reference in New Issue
Block a user