Is a member binding expression really an expression in C#?
See original GitHub issueA member binding expression looks like this:
.something
This is a valid expression according to the grammar, but I don’t think it is.
It’s used in conditional access expression (a?.b
). The grammer pretends that any expression can follow the ?
, but only a member access or array access can.
So presumably, the same is true for array access. [1]
would be a valid statement according to this grammar, while I think it shouldn’t be.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Expression.Bind() - what does it actually do? - Stack Overflow
PropertyOrField() call, but it does roundtrip back to reflection to find member by name, where as I typically already have MemberInfo instance.
Read more >Scheme - Expressions
A Scheme expression is a construct that returns a value, such as a variable reference, literal, procedure call, or conditional. Expression types are...
Read more >Fun with Expression Trees and property binding - Aaron Powell
NET 4.0 version is not really an Expression Tree any more, it's actually a Statement Tree and it's scarily close to a full...
Read more >Expressions - C# language specification - Microsoft Learn
An expression is a sequence of operators and operands. ... In C# the binding of an operation is usually determined at compile-time, ...
Read more >Automatic Data Binding via Expression Trees - CodeProject
Experimenting with C# expression trees for creating data-bound UI's from code.
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 Free
Top 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
Okay, I have a fix incoming for this that also solves #131. It doesn’t add any new conflict rules and actually drops the Roslyn file parsing issues from 27 files to 25 and does not introduce any new example failures. PR in a few minutes.
I now better understand how conditional access expressions (
a?.b
) are parsed in Roslyn, and why a member binding expression (.something
) was an expression. Of course.something
is not a valid expression in itself, but it is used in many things that take an expression.a?.b()
only performs the invocation onb
ifa
is not null, so it’s parsed likea?(.b())
. This means that the parse tree looks like this:As you see, the
member_binding_expression
is moved down into theinvocation_expression
.invocation_expression
consists of an invocation on any expression, and here it invokes amember_binding_expression
, somember_binding_expression
should be a type of expression.This also means that (in Roslyn), the right part of the conditional_access_expression can be many things, not only a member_binding_expression. So that is why the right arm of the conditional_access_expression could contain any expression.