Extracting custom field conversion for use in other places
This commit is contained in:
parent
1709631965
commit
47aa8c2aaa
@ -198,7 +198,7 @@ namespace TelegramBotBase
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
|
||||
CustomConversionChecks(form, p, f);
|
||||
Tools.Conversion.CustomConversionChecks(form, p, f);
|
||||
|
||||
}
|
||||
catch
|
||||
@ -240,33 +240,7 @@ 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>
|
||||
|
||||
38
TelegramBotBase/Tools/Conversion.cs
Normal file
38
TelegramBotBase/Tools/Conversion.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Tools
|
||||
{
|
||||
public static class Conversion
|
||||
{
|
||||
public 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user