Fix usages of decimal.TryParse
This commit is contained in:
@@ -864,6 +864,17 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.False((bool?)result);
|
Assert.False((bool?)result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void Misc__ProductWithStringDecimals_EqualsFalse()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("$1109", "1933");
|
||||||
|
evaluationContex.SetVariable("$1150", "02.00000");
|
||||||
|
string expression = "$1109 * $1150";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.Equal(3866.00000M, result);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Misc
|
#endregion Misc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
// Decimal
|
// Decimal
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
leftValue = null;
|
leftValue = null;
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
rightValue = null;
|
rightValue = null;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
decimal decValue;
|
decimal decValue;
|
||||||
if (decimal.TryParse(text, out decValue))
|
if (decimal.TryParse(text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decValue))
|
||||||
{
|
{
|
||||||
return decValue != 0;
|
return decValue != 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (value is string)
|
if (value is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)value, out decimal dec) == false)
|
if (decimal.TryParse((string)value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
#region Creator
|
#region Creator
|
||||||
|
|
||||||
private ITokenizer _tokenizer;
|
private readonly ITokenizer _tokenizer;
|
||||||
|
|
||||||
public Parser(ITokenizer tokenizer)
|
public Parser(ITokenizer tokenizer)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user