question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is a member binding expression really an expression in C#?

See original GitHub issue

A 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:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
damiengcommented, Nov 10, 2020

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.

0reactions
Sjordcommented, Mar 25, 2021

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 on b if a is not null, so it’s parsed like a?(.b()). This means that the parse tree looks like this:

  • conditional_access_expression
    • identifier
    • invocation_expression
      • member_binding_expression
      • argument_list

As you see, the member_binding_expression is moved down into the invocation_expression. invocation_expression consists of an invocation on any expression, and here it invokes a member_binding_expression, so member_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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found