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

ReSharper support for C# 7 and C# 7.1Today, 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:

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 Code Editing | C# | Code Style, then Code Body, we can choose our preferred style (block body or expression body).
Code body code style

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.
Use expression body code analysis and quick-fix

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

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 C# 7.0 and 7.1 support in ReSharper – Expression-bodied everything

  1. Marcel Popescu says:

    Why is the clip showing Name still with the squiggles after refactoring?

Leave a Reply

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