Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline LINQ Comments in VB.NET

Tags:

vb.net

linq

Is there some way to insert inline code comments in LINQ in VB.NET?

Please see line 2 in the below as an example of where an inline comment would be desirable

Dim Jobs = (From X In DB.Jobs_Select(SearchStr, RequiresFilter)
    Where X.JobStatusID < 2   -- **** INSERT INLINE COMMENT HERE  ****
    Order By
        X.JobPriorityID Descending,
        If(X.TargetDate, Date.MaxValue),
        X.NeedsLit Descending,
        X.HasOldArtRequests Descending,
        X.HasOldLicRequests Descending
    )

This is trivial in SQL code and frankly, very useful as SP's become complex. It would be nice to be able to perform the same cross-developer communication in LINQ to SQL.

Update

Here is a test condition for you.

 Dim L As New List(Of KeyValuePair(Of Integer, Integer))

 Dim a = (From X In L
            Where X.Key > 5 'test comment
            Order By X.Value)
like image 315
Brian Webster Avatar asked Oct 19 '12 20:10

Brian Webster


People also ask

What are inline code comments?

Inline comments are all comments not included in doc blocs. The goal of in line commenting is to explain code in context. Such explanation may take many different forms. Comments that are written in a readable and narrative style, especially when explaining a complex process, are encouraged.

How do you comment out a line in VB?

In VB . NET, you write a comment by writing an apostrophe ' or writing REM . This means the rest of the line will not be taken into account by the compiler.

How does VB.NET treat a comment during compilation?

The compiler usually ignores comments when compiling the code. In VB.NET, comments start with a single apostrophe ' . 'This is a comment in VB.NET.


1 Answers

Ok folks, here is the official answer - not possible in VB. Proof.

It is REALLY annoying in VB that you cannot add inline comments to multiline LINQ statements!

And more information:

The bad news is that this wouldn't be trivial to implement. Limitations about single-lines and comments are built into the current VB parser at too low a level. It'd require a complete rewrite of the VB parser.

The good news is that we've embarked upon such a rewrite (codenamed "Roslyn" -- there have been several articles and talks about it). It's still a way off and we're not making commitments about what/when at this stage.

-- Lucian Wischik, VB language PM

like image 86
Neolisk Avatar answered Sep 26 '22 23:09

Neolisk