Top VS2015 Extensions: C# Essentials

Along with our own release of Visual Studio 2015, many other extensions and tools are becoming available. I'm going to highlight a couple my favorites over the coming weeks - hopefully you find one or two that are useful to you in your own work.

The first one I'm going to highlight is C# Essentials by our own Dustin Campbell. C# Essentials is the perfect epitome of a great extension: it's lightweight, it does one task really well, and it integrates cleanly into the IDE. Its purpose is to help you update your existing code to take advantage of the new language capabilities in C# 6. Learning something new is one thing - putting it into practice unconsciously is another. In the code below, can you spot all the ways that this can be improved with C# 6?

using System;

namespace BusinessLibrary  
    public class Customer
        public string FirstName { get; private set; }
        public string LastName { get; private set; }
        public DateTime AccountNumber { get; private set; }

        public Customer(string firstName, string lastName, DateTime accountExpiry)
            if (accountExpiry == null)
                throw new ArgumentNullException("accountExpiry");

            this.FirstName = firstName;
            this.LastName = lastName;
            this.AccountNumber = accountExpiry;

        public override string ToString()
            return string.Format("{0} {1}", this.FirstName, this.LastName);

The C# Essentials extension adds a number of lightbulbs to the editor that identify places where you can update your code. In the example above, these include:

  • String interpolation instead of numbered placeholders
  • nameof expressions
  • Expression-bodied members
  • Getter-only auto-properties

Having the editor remind you as you code is about the best tutorial you could imagine, and it's helped me get finger-comfortable with more of C# 6. Here's an example of how it corrects the code above:
C# Essentials converting to interpolated string

Try it out and see what you think. The source code is also a really good basis for learning how to build analyzers, code fixes and refactoring extensions for Visual Studio - and it's all up on GitHub for you to clone at your leisure.