Eval-Expression.NET
Eval-Expression.NET copied to clipboard
Seems doesn't support User-defined Implicit type conversion operators?
The following statement will report an error.
using Newtonsoft.Json.Linq;
static void Main(string[] args)
{
var context = new EvalContext();
context.RegisterType(typeof(JArray));
context.Execute(@"new JArray().Contains(""D"")");
}
The error is as follows
Z.Expressions.Compiler.Shared.EvalException
HResult=0x80131500
Message=Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 12 near ".Contains(\"D\")".
Source=Z.Expressions.Eval
StackTrace:
at .(ExpressionScope , Expression , Type , String , List`1 , Boolean , List`1 , SyntaxNode , Expression& )
at .(ExpressionScope , SyntaxNode , Type , Expression , List`1 )
at .(ExpressionScope , SyntaxNode , Expression , Boolean )
at .(ExpressionScope , SyntaxNode , Expression , Boolean )
at .(ExpressionScope , SyntaxNode , Expression , Boolean )
at Z.Expressions.CodeCompiler.CSharp.ExpressionParser.ParseSyntax(ExpressionScope scope, SyntaxNode node, Type resultType)
at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , ExpressionScope , String , Boolean , Boolean )
at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , Boolean , Boolean , Boolean )
at Z.Expressions.EvalContext.Execute[TResult](String code)
at SomeTest.Program.Main(String[] args) in E:\Desktop\Program\C#\SomeTest\Program.cs:line 66
此异常最初是在此调用堆栈中引发的:
[外部代码]
SomeTest.Program.Main(string[]) (位于 Program.cs 中)
JArray.Contains(JToken T) only accepts JToken, so EvalContext considers No applicable member
But we know that Newtonsoft.Json.Linq defines implicit type conversion from String to JToken, and this statement works properly in VS.
Hello @cesaryuan ,
Thank you for reporting, we will look at it.
Best Regards,
Jon
Hello @cesaryuan ,
Just to let you know that there is currently no short-term plan to make it works.
We will look again in around 2-3 months to add better support to implicit type, but at this moment, this will be a limitation of our library.