dynamicexpresso / DynamicExpresso

C# expressions interpreter
http://dynamic-expresso.azurewebsites.net/
MIT License
2.02k stars 379 forks source link

Null check for property of parameter with late binding does not work anymore #325

Open AndreasKorn opened 5 days ago

AndreasKorn commented 5 days ago

Checking a property of an input (parameter) object for null stopped working in 2.17.1. This worked fine in 2.16.1.

  var options = InterpreterOptions.DefaultCaseInsensitive | InterpreterOptions.LambdaExpressions | InterpreterOptions.LateBindObject;
  var interpreter = new Interpreter(options);

  var input = new
  {
    //Prop1 = (object?)null, // works
    Prop1 = new { }, // does not matter what type
  };
  var expressionDelegate = interpreter.ParseAsDelegate<Func<object, bool>>($"input.Prop1 == null", "input")!;
//  var expressionDelegate = interpreter.ParseAsDelegate<Func<object, bool>>($"input.Prop1 == (object)null", "input")!; // also works
  var value = expressionDelegate(input); // exception

With 2.17.1 this throws an exception: _System.InvalidCastException : Unable to cast object of type '<>f_AnonymousType2' to type 'System.Nullable`1[System.Boolean]'.

davideicardi commented 1 day ago

Thank you for the bug report. We will try to investigate.

@metoule Do you have any idea of which change could have caused this behavior?

AndreasKorn commented 1 day ago

Unfortunately not. I only noticed the expression tree generated looks very different with the new version.

metoule commented 11 hours ago

I've tracked the change in behavior to #296. I'll try to investigate why it caused the new issue.