Named tuple inference, leading digit separator, non-trailing named arguments – VB.NET 15.3 and 15.5 language features in ReSharper and Rider

A while ago, we did a blog series about C# 7.0, 7.1, 7.2, and C# 7.3 language features. It’s high time we did something similar for VB.NET!

The latest ReSharper 2018.3 EAP and Rider 2018.3 EAP come with VB.NET 15.3 and 15.5 language support for named tuple inference, the leading digit separator, non-trailing named arguments, and the Private Protected access modifier. Let’s have a look at them, shall we?

Setting the VB.NET language version

To ensure that our project supports using these new VB.NET language features, we will have to specify the LangVersion in our .vbproj project file and either set it to one of the available VB.NET language versions (or latest):

Once that is done, we can start using the latest VB.NET version in our project.

Leading hex/binary/octal digit separator

In terms of language features, let’s start with one that improves readability of our code. In Visual Basic 2017, support was added for using an underscore character (_) as a digit separator. While that improved readability, there was one place in the syntax where we could not use _: between the prefix and hexadecimal, binary, or octal digits.

In VB.NET 15.5, it is now possible to make use of the _ digit separator  there as well:

Named tuple inference

Visual Basic 2017 introduced support for tuples – lightweight structures that we can use to pass data around. Tuples are used very often when returning multiple values from a method call, without having to create a separate class to do so.

Tuples can also be used to create such lightweight data structure in code:

Our person would now be a tuple with a FirstName and LastName element.

In VB.NET 15.3, creating the above tuple becomes easier. Instead of having to add the element names (FirstName and LastName): when initializing the tuple, Visual Basic will now infer the element names:

This removes some clutter from our code, and improves readability.

Non-trailing named arguments

VB.NET 15.5 introduces support for non-trailing named arguments. They allow us to mix non-named arguments with named arguments when calling a constructor or method, as long as the order of parameters is respected.

For example, let’s assume we have a Person class defined like this:

Before VB.NET 15.5, if we did not want to pass the email argument when using this constructor, we’d write our code like this:

What is the argument that we are setting to Nothing here? We’d always need tooling to tell us by hovering over the call and looking at the arguments our constructor accepts.

With VB.NET 15.5, we can use named arguments anywhere in the method call, as long as we respect the order of arguments. This makes it more visible for ourselves and fellow developers to see which argument we are setting to Nothing:

Private Protected access modifier

VB.NET 15.5 introduces a new member access modifier: Private Protected. Just like a Protected member, a Private Protected member is accessible by all members in its containing class and by types derived from the containing class.

The main difference is that Private Protected members are only accessible in their containing assembly, and not outside. In summary, that gives the following access modifiers in VB.NET 15.5 and up:

Access modifier Visibility
Public Any code that can see a public element, can access the element.
Protected Code in the class that declares a protected element, or a class derived from it, can access the element.
Friend Code in the assembly that declares a friend element, can access the element.
Private Code in the type that declares a private element, including code within contained types, can access the element.
Protected Friend Code in the same class or the same assembly as a protected friend element, or within any class derived from the element’s class, can access the element.
Private Protected Code in the class that declares a private protected element, or code in a derived class in the same assembly as the base class, can access the element.

Download ReSharper 2018.3 EAP or Rider 2018.3 EAP and give it a try! We’d love to hear your feedback!

About Maarten Balliauw

Maarten Balliauw is a Developer Advocate at JetBrains, working on .NET tools and Space. He focuses on .NET, Azure, web technologies and application performance. Maarten is a frequent speaker at various national and international events. In his free time, he brews his own beer. Follow him on Twitter or check out his personal blog.
This entry was posted in How-To's and tagged , , , . Bookmark the permalink.

2 Responses to Named tuple inference, leading digit separator, non-trailing named arguments – VB.NET 15.3 and 15.5 language features in ReSharper and Rider

  1. N3N Lee says:

    I am a developer lee of n3n.

    I am developing wpf.

    I am trying to do wpf development using the rider tool,
    Is it possible to apply it to the UI immediately after modifying xaml code during project debugging?
    Without rebuilding

    thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *