3 ms·
> If they would bake in that expression within NullReferenceException, well that would be so good... CallerArgumentExpression doesn't do that, though. I think
by jmull 5y ago
> If they would bake in that expression within NullReferenceException, well that would be so good...
CallerArgumentExpression doesn't do that, though.
I think you could maybe use it to do something explicit, like...
someexpr.CheckNotNull().DoSomethingWithSomeExpr()
where CheckNotNull() somehow uses CallerArgumentExpression to capture "someexpr" so that if someexpr was null, the exception could include the actual expression in the exception message. But that means decorating code with CheckNotNull() all over the place, which really limits this.
What you really want here is a good call stack -- maybe with expressions, source lines, local variable values, etc.