Support null-conditional operator in assignment statements.
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
The null-conditional operator was an awesome recent addition to VB and I hope it can be extended to the following:
```vb
Public Module Module1
Public Class CTest
Public Value As String
End Class
Public Sub Main()
Dim test As CTest
test?.Value = "foo" '<--- compiler doesn't like this.
End Sub
End Module
```
Compiler says:

Unless I am missing something, couldn't this:
```vb
test?.Value = "foo"
```
...be treated as this:
```vb
If test IsNot Nothing Then
test.Value = "foo"
End If
```
Without this ability today, **if you want to set a member on a possibly-null object reference, you have to write a method that takes a parameter and sets the value, then call that method using the null-conditional operator (which feels like a lot of ceremony for a simple thing like setting a field):**
```vb
Public Module Module1
Public Class CTest
Public Value As String
Public Sub SetValue(ArgValue As String) '<-- must define this.
Me.Value = ArgValue
End Sub
End Class
Public Sub Main()
Dim test As CTest '<--- test is null here.
test?.SetValue("foo") '<--- compiler is OK with this.
test?.Value = "foo" '<--- ...but doesn't like this.
End Sub
End Module
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.