Adding some conversion checks for JSON State serialization
This commit is contained in:
parent
c8936d0748
commit
e2c485aede
@ -198,6 +198,8 @@ namespace TelegramBotBase
|
|||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
CustomConversionChecks(form, p, f);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
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>
|
/// <summary>
|
||||||
/// Saves all open states into the machine.
|
/// Saves all open states into the machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user