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

[Revived] Null-propagating operator ?. in Expression Trees #3717

Closed
mkosieradzki opened this issue Jun 27, 2015 · 3 comments
Closed

[Revived] Null-propagating operator ?. in Expression Trees #3717

mkosieradzki opened this issue Jun 27, 2015 · 3 comments

Comments

@mkosieradzki
Copy link
Contributor

I would like to revive and old from codeplex https://roslyn.codeplex.com/discussions/571077 and provide an implementation that does not required modifiaction from BCL but will be really handy for at least some scenarios (not all!).

I have implemented such an approach in my scripting engine basing on Roslyn (as frontend) and LINQ Expressions as a backend.

Expression.Invoke(Expression.Lambda(Expression.Condition(Expression.Equal(parm, Expression.Constant(null)), Expression.Default(rtype), translatedWhenNotNull), parm), translatedExpression);

It utilizes existing mechanism declaring inline lambda and invoking it. It preserves single-evaluation semantics, without requiring special support from BCL.

I am fully aware inline lambdas are actually blackboxes for many LINQ providers, but such a blackbox is still better than not supporting such a useful operator at all!

@svick
Copy link
Contributor

svick commented Jun 27, 2015

The more general request of extending expression trees with features that are allowed in normal expressions is #2060. I think that it makes more sense to consider that proposal as a whole, instead of adding the features one by one.

@mkosieradzki
Copy link
Contributor Author

@svick
I aggree. I was unable to find previous issue because I was searching for "null-propagating" as in original issue instead of "null-coalescing" ;). Thanks for pointing out proper issue.

@douglasg14b
Copy link
Contributor

Correctly linking #2060 which is redirected to: dotnet/csharplang#2545

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

No branches or pull requests

4 participants