Null propagation operator (?) and passing null values are failing
See original GitHub issueHi,
(1) Getting an exception when trying to use null propagation operator: DynamicExpresso.Exceptions.ParseException Neither of the types ‘null’ and ‘Boolean’ converts to the other (at index 31). This is in line (2) on Parse stage.
(2) Getting an exception when passing a null value via parameter class (line 2). Need to specify a type name as a second parameter one more time to work it out. Basically when using a name/value Parameter constructor will throw an exception if provided value is null, the other constructor (name/type/value) won’t throw. This behaviour is unclear because parameter type was already provided on Parse stage and looks like it should be possible just to provide a null value.
class Scope {
public bool Value { get; set; }
}
var interpreter = new Interpreter();
(1) var func = interpreter.Parse("Scope?.Value == true", new Parameter("Scope", typeof(Scope)));
(2) var result = func.Invoke(new Parameter("Scope", typeof(Scope), null));
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
c# - Null propagation operator and extension methods
I've been looking at Visual Studio 14 CTP along with C# 6.0 and playing with the null-propagation operator. However, I couldn't find why...
Read more >Async/Await Calls Gotcha with the CSharp ? Null Propagator
Let's break this down: The ? (Elvis) operator in C# propagates the null value in JsEditorInterop and short circuits the call to SetFocus()...
Read more >The '= NULL' Mistake and other SQL NULL Heresies
The SQL Prompt Best Practice rule checks whether a comparison or expression includes a NULL literal ('NULL'), which in SQL Server, ...
Read more >Null Propagation Operator and Unity (?) : r/Unity3D
The short answer is that the Null-Coalescing operator checks of it's actually null and doesn't call units overloaded Equals() operator like the ...
Read more >c# - Is it unreasonable to expect Any() *not* to throw a null ...
isEmpty throws System.ArgumentNullException: Value cannot be null . The expectation seems to be that you won't be passing undefined values for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@halamah Just released v2.9.2
For the second issue, it’s because the
Parameter
class is used to declare both parameters (for which the type is required) and arguments (for which the type can be inferred from the Parameter). If the object value is null, there’s no way to detect its type, which is why anArgumentNullException
is thrown.Note that you can directly invoke the lambda with the arguments’ values, without the need of creating
Parameter
instances: