I have the following code that works fine in VB.net ( VS 2012 ). Note that m.Listen is returning an IObservable(of Maybe(of NominalObject))
Dim d As IDisposable = (From x In m.Listen(Of Maybe(Of NominalObject))()
From y In x
Select New LAPViewCommands(y)).
BindToControl(Me, Function(x) x.ViewModel)
d.DisposeWith(Me)
This is part of a custom user control and I have some extension methods for
binding IObservables to models. However the details are irrelevant. When
I change the code to
(From x In m.Listen(Of Maybe(Of NominalObject))()
From y In x
Select New LAPViewCommands(y)).
BindToControl(Me, Function(x) x.ViewModel).
DisposeWith(Me)
I have a compile error. Note there is no problem with the fluent syntax.
m.
Listen(Of Maybe(Of NominalObject)).
SelectMany(Function(x) x.Select(Function(y) New LAPViewCommands(y))).
BindToControl(Me, Function(x) x.ViewModel).
DisposeWith(Me)
Is this problem a strange edge case of the VB.NET parser or is there something
important here I’m missing? In summary the question is. Why can’t I bracket a
LINQ query expression and then use fluent extension methods that return void
The problem is that your expression doesn’t start with an identifier.
It’s a limitation of VB.Net and not limited to LINQ query expressions.
Compare the following C# code (
Dumpis an extension method)which will work fine. Here’s the VB.Net equivalent (which more or less looks the same):
and each of the three statements will throw a syntax error.
You can fix it by using the
Callstatement: