Adding some conversion checks for JSON State serialization

This commit is contained in:
FlorianDahn 2021-04-25 15:51:19 +02:00
parent c8936d0748
commit e2c485aede

View File

@ -198,6 +198,8 @@ namespace TelegramBotBase
catch (ArgumentException ex)
{
CustomConversionChecks(form, p, f);
}
catch
{
@ -238,6 +240,35 @@ namespace TelegramBotBase
}
private static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, System.Reflection.PropertyInfo f)
{
//Newtonsoft Int64/Int32 converter issue
if (f.PropertyType == typeof(Int32))
{
int i = 0;
if(int.TryParse(p.Value.ToString(), out i))
{
f.SetValue(form, i);
}
return;
}
//Newtonsoft Double/Decimal converter issue
if(f.PropertyType == typeof(Decimal) | f.PropertyType == typeof(Nullable<Decimal>))
{
decimal d = 0;
if(decimal.TryParse(p.Value.ToString(), out d))
{
f.SetValue(form, d);
}
return;
}
}
/// <summary>
/// Saves all open states into the machine.
/// </summary>