The following code throws an EvalException:
var compiledExpr = Z.Expressions.Eval.Compile("$\"{d:yyyyMMdd}\"", new Dictionary<string, Type> { ["d"] = typeof(DateTime?) });
I was expecting it to compile similar to:
System.Linq.Expressions.Expression<Func<DateTime?, string>> expr = d => $"{d:yyyyMMdd}";
var compiledExpr = expr.Compile();
var today = compiledExpr(DateTime.Now); // Returns "20260724"
var emptyString = compiledExpr(null); // Returns ""
The exception is only thrown if a format specifier is used, and only when the expression resolves to a Nullable<> type.
The following code throws an
EvalException:I was expecting it to compile similar to:
The exception is only thrown if a format specifier is used, and only when the expression resolves to a
Nullable<>type.