Code Generation Improvements in ReSharper 7
If there was a competition between different ReSharper subsystems on which one produces most value relative to developer effort, the Generate action would win that competition outright. And, needless to say, in the 7.0 release we have added a couple of new features and improvements to ReSharper’s intuitive code generator.
Generate Partial Methods
Many code-generating frameworks produce code made using partial classes, with the assumption that developers can augment generated functionality by implementing partial methods when needed. For example, the Entity Framework does this (in non-Code-First scenarios, of course) by defining entity classes as
ReSharper now supports this scenario. To use it, create a
partial declaration of a class, then choose Generate|Partial Methods:
Now, simply pick the partial methods that you want to implement:
All the partial methods are consequently stubbed out in the target class, ready for you to implement.
Improvements in Generate Equality Members
When comparing types, many of our users wanted to control the way type checks were performed. So, by popular demand, the Generate Equality Members dialog now has three different options for implementing the type comparison:
Depending on which of the three options you choose in the above, the condition for checking the type in the
Equals() method will appear as one of the following:
Type exactly same as
Type exactly as owner type:
Type is of owner type or subtype:
Generate Equality Comparer
In addition to the inline equality implementation for a particular class, ReSharper 7 comes with a brand-new action called Generate Equality Comparer. The goal of this action is to generate a separate class that implements the
IEqualityComparer<T> interface. This is useful for creating specific comparison criteria, as well as for instances where an
IEqualityComparer is explicitly required by a particular API.
For example, given a simple
Person class with two properties, we can fire up the action:
and, after picking the members for comparison,
Person gets the following private inner class:
In addition, the option to generate the static instance of the comparer adds the following field to the
Support for INotifyPropertyChanged
And one last thing… if you’ve got a class that implements the
INotifyPropertyChanged or inherits from a class that supports property change notifications (e.g., Prism’s
NotificationObject), the Generate|Properties action offers an option to implement properties with change notification calls:
By the way, support for INotifyPropertyChanged in ReSharper 7 is more than just generation, so make sure to read more about this.
Subscribe to Blog updates
Thanks, we've got you!
Another Look into the Future with Rider’s Predictive Debugger
In the 2023.2 release cycle, we’ve introduced the Predictive Debugger in ReSharper, which gives you predictions about code paths and variables beyond the current execution pointer. We’ve written extensively about its advantages compared to alternative debugging strategies like thorough thinking, log…
Visualize Entity Framework Relationships and Additional Query Analysis in ReSharper 2023.3
A lot of teams are using Entity Framework or EF Core to work with their database. As an Object-Relational Mapper (ORM), it bridges objects in code to a relational database model, so that as a developer you don’t have to worry too much about the actual database. We all know: that’s not entirely tr…
Automatically Analyze ASP.NET Core Performance With Dynamic Program Analysis
Slow web pages may make your users or customers abandon your web application, even before they’ve had a proper look at it. You’ve likely also been frustrated working with a web application that is slow to load. The good news is that the latest versions of ReSharper and JetBrains Rider’s Dynamic P…
OSS Power-Ups: MassTransit – Webinar Recording
The recording of our webinar, OSS Power-Ups: MassTransit, with Chris Patterson, is available. This was the thirteenth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webinars.…