bruce-dunwiddie / data-eval

.Net Library for Evaluating Expressions at Runtime
Apache License 2.0
14 stars 4 forks source link

Handle Nullable Value Types #35

Open bruce-dunwiddie opened 1 year ago

bruce-dunwiddie commented 1 year ago

There's probably a missing nullable type check along with correct cast handling in the Linq Expression tree.

var evaluator = new Evaluator(
    "return someNumber");

evaluator.SetVariable(
    "someNumber",
    null,
    typeof(decimal?));

Assert.IsNull(evaluator.Eval<decimal?>());

System.InvalidCastException : Null object cannot be converted to a value type.

bruce-dunwiddie commented 1 year ago

This passes however:

var evaluator = new Evaluator(
    "return someNumber");

evaluator.SetVariable(
    "someNumber",
    null,
    typeof(decimal?));

Assert.IsNull(evaluator.Eval());