Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: 'Safe Invocation' operator [Discussion] [Proposal] #2200

Closed
tangelov opened this issue Feb 6, 2019 · 3 comments
Closed

Comments

@tangelov
Copy link

tangelov commented Feb 6, 2019

Hi guys,

I propose an extension to the 'Safe Navigation' ? operator. If the nested expression does not have a value the parent expression would evaluate to null without calling the method e.g:

Given we have a method signature int DoStuffAndGetValue(int arg)

The new syntax would be used like so var a = DoStuffAndGetValue(parent?.child.child?)

Such an operator would avoid the need of assigning a variable with parent?.child.child? or repeating the code with a ternary operator. It looks like a natural extension of the 'Safe Navigation' operator to me.

Regards,
Teodor

@tangelov tangelov changed the title Feature Request: 'Safe Invocation' operator Feature Request: 'Safe Invocation' operator :Discussion :Proposal Feb 6, 2019
@tangelov tangelov changed the title Feature Request: 'Safe Invocation' operator :Discussion :Proposal Feature Request: 'Safe Invocation' operator [Discussion] [Proposal] Feb 6, 2019
@HaloFour
Copy link
Contributor

HaloFour commented Feb 6, 2019

Here's a relevant discussion on this subject that happened on the Roslyn repo:

dotnet/roslyn#5961

@jnm2
Copy link
Contributor

jnm2 commented Feb 6, 2019

Duplicate of #842, very close to #433.

@YairHalberstadt
Copy link
Contributor

Closing as duplicate of #843 and #433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants