测试报告导出修改
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -23,7 +24,7 @@ namespace Common.Tools
|
||||
{
|
||||
foreach (var kvp in processedVariables)
|
||||
{
|
||||
expr.Parameters[kvp.Key] = kvp.Value;
|
||||
expr.Parameters[kvp.Key] = NormalizeValue(kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +96,29 @@ namespace Common.Tools
|
||||
return (processedExpression, newVariables);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 归一化变量取值:输入变量的值常以字符串形式保存(如 "10"),
|
||||
/// 若直接参与比较,NCalc 会按字符串逐位比较("10" > "5" 为假),
|
||||
/// 导致大于/小于判断失真。此处将可解析为数字/布尔的字符串转换为对应类型,
|
||||
/// 使比较按数值语义进行;无法解析的字符串保持原样。
|
||||
/// </summary>
|
||||
private static object? NormalizeValue(object? value)
|
||||
{
|
||||
if (value is string s)
|
||||
{
|
||||
if (double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var d)
|
||||
|| double.TryParse(s, out d))
|
||||
{
|
||||
return d;
|
||||
}
|
||||
if (bool.TryParse(s, out var b))
|
||||
{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// 检查字符串是否包含中文字符
|
||||
private static bool ContainsChinese(string text)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user