Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line break in method chains in VB.NET

Tags:

vb.net

I'm attempting to put line breaks in the following method chain in VB.NET, but I have the syntax incorrect:

HasRequired(Function(x) x.Issue).WithMany(Function(x) x.EntityNotes).HasForeignKey(Function(x) x.IssueID)

I would like something similar to:

HasRequired(Function(x) x.Issue)
   .WithMany(Function(x) x.EntityNotes)
   .HasForeignKey(Function(x) x.IssueID)
like image 935
Mike Cole Avatar asked Sep 03 '25 03:09

Mike Cole


1 Answers

In VB.Net, you used to always need _ to continue a line. This is now often optional, but can always be added:

HasRequired(Function(x) x.Issue) _
   .WithMany(Function(x) x.EntityNotes) _
   .HasForeignKey(Function(x) x.IssueID)

As of Visual Studio 2010, however, you can leave this off in many cases, and the compiler will correctly determine whether the new "line" is part of the preceeding line.

This is covered under Typographic and Code Conventions in the language documentation.

like image 192
Reed Copsey Avatar answered Sep 05 '25 01:09

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!