C# 7.0 and 7.1 support in ReSharper – Expression-bodied everything

Posted on by

Today, we continue our blog series on ReSharper support for C# 7.0 and C# 7.1. The previous post touched on throw expressions (spec) and ReSharper’s inspections, quick-fixes and context actions around these language features.

Today, let’s talk about expression-bodied methods, properties, local functions, constructors, destructors and event accessors. Or in short: expression-bodied “everything”!

In this series:

Expression-bodied “everything”

In C# 6.0, expression-bodied methods and properties were introduced. In short, one-line methods or simple properties can be written with a simple lambda syntax, instead of having to write a full body:



// Before: public string FullName { get { return FirstName + " " + LastName; } } // After: public string FullName => FirstName + " " + LastName;

C# 7.0 extends expression-bodied members by allowing “everything” to be expression-bodied: methods, properties, local functions, but also constructors, destructors and event accessors. In the ReSharper settings under, then, we can choose our preferred style (block body or expression body).

Once configured, ReSharper will suggest (or hint, warn or error, depending on our settings here) using a block body or expression body. A quick-fix can rewrite things for us.



Download ReSharper Ultimate or check out Rider that takes advantage of ReSharper’s language support updates. We’d love to hear your thoughts.