diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs index 7096000..410de80 100644 --- a/TelegramBotBase/SessionBase.cs +++ b/TelegramBotBase/SessionBase.cs @@ -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 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 d = 0; - if(decimal.TryParse(p.Value.ToString(), out d)) - { - f.SetValue(form, d); - } - return; - } - - - } - + /// diff --git a/TelegramBotBase/Tools/Conversion.cs b/TelegramBotBase/Tools/Conversion.cs new file mode 100644 index 0000000..b9e40da --- /dev/null +++ b/TelegramBotBase/Tools/Conversion.cs @@ -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 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 d = 0; + if (decimal.TryParse(p.Value.ToString(), out d)) + { + f.SetValue(form, d); + } + return; + } + + + } + + } +}