In C#, I have some code that looks like:
(await GetBoolAsync()).ShouldBeTrue();
ShouldBeTrue()
is an extension method from the Shouldly library that operates on Booleans.
VB.NET doesn't seem to like wrapping the Await keyword in parenthesis:
(Await GetBoolAsync()).ShouldBeTrue()
The compiler reports a syntax error on the opening parenthesis at the beginning of the line. I can work around it by declaring an intermediate variable, but is there a way to achieve this in one line like C#?
A full console application to reproduce this:
Imports System.Runtime.CompilerServices
Module Module1
Sub Main
End Sub
Async Function Test() As Task
(Await GetBoolAsync()).ShouldBeTrue()
End Function
Function GetBoolAsync() As Task(Of Boolean)
Return Task.FromResult(True)
End Function
<Extension()>
Public Sub ShouldBeTrue(x As Boolean)
End Sub
End Module
The error is very unhelpful:
error BC30035: Syntax error.