首先,我在.Net方面没有太多经验 - 特别是在过去的7年里.
我正在尝试开发一个应用程序,并将合并另一个库(https://github.com/Giorgi/Math-Expression-Evaluator)
那个库允许我评估数学表达式Evaluate("a+b", a: 1,b: 1).方法签名是public decimal Evaluate(string expression, object argument = null)
我真的只是寻找文档和更多信息的指针..感谢您的任何事情.
编辑:抱歉..故意留下它广泛,因为我不是在寻找人为我做我的工作..似乎无法找到一个起点做我自己的研究.
该方法称为
dynamic engine = new ExpressionEvaluator() ;
engine.Evaluate("(c+b)*a", a: 6, b: 4.5, c: 2.6)) ;
Run Code Online (Sandbox Code Playgroud)
在Evalute()的主体中是这个代码(它将该参数转换为字符串字典,十进制对.
if (argument == null)
{
return new Dictionary<string, decimal>();
}
var argumentType = argument.GetType();
var properties = argumentType.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.CanRead && IsNumeric(p.PropertyType));
var arguments = properties.ToDictionary(property => property.Name,
property => Convert.ToDecimal(property.GetValue(argument, null)));
return arguments;
Run Code Online (Sandbox Code Playgroud)
我希望能够做的是解析像"a:1,b:2"之类的字符串并将其转换为与该Evaluate()签名匹配的对象.