Operator ?: seams to evaluate both sides of expression.
See original GitHub issueExpression
xx == null ? 0 : xx.SomeProperty
failed with exception “No property or field SomeProperty
exists in type Object
(at index 22).”
The problem is that the expression xx is null.
If I change the expression to “xx == null ? 1 : 2” it is evaluated and the result is 1.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Does the logical operator || executes both sides before ...
The right hand side of either the '&&' and '||' logical operators will only be evaluated and returned if the left hand side...
Read more >The mechanical evaluation of expressions
We shall consistently distinguish between "operators" and "functions" as follows. An operator is a sub- expression of a (larger) expression appearing in a....
Read more >Chapter 5: Expressions -- Valvano
The basic problem in evaluating expressions is deciding which parts of an expression are to be associated with which operators.
Read more >Chapter 15. Expressions
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to...
Read more >Operators and Expressions in Python
Logical Operators. The logical operators not , or , and and modify and join together expressions evaluated in Boolean context to create more...
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
The problem is that the parser has no idea what
xx
is.The parser is not evaluating xx.SomeProperty, the error is a parse-time error. You are assigning a null value to xx, and without any type information the parser cannot know what xx is.
null
is treated as type Object and so in the process of parsing, it tries to find SomeProperty on type Object, which of course fails.This is why C# forbids assigning a null value using the var expression.
So you need to pass in the type information explicitly using the
SetVariable(string, object, Type)
overload. Suppose you have SomeClass with SomeProperty:This will make your code work as expected.
Note however that assigning null to a typed variable does not work:
This is because a typed variable set to null will actually be passed as a null object (without type information) into SetVariable, it acts as if it had no type at all, hence the need for an overload explicitly allowing you to set the type.
You are right. Using SetVariable with type parameter make it work. Thanks.