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.
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)
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With