What's New in ReSharper 4.0
Full Support for C# 3.0 and LINQ
ReSharper 4.0 Full Edition and C# Edition provide comprehensive support for C# 3.0, including LINQ, implicitly typed locals and arrays, extension methods, automatic properties, lambda expressions, object & collection initializers, anonymous types, expression trees, and partial methods. ReSharper not only analyzes the new constructs, but provides C# 3.0-related enhancements in a number of areas:
- New suggestions helping migrate to C# 3.0, including "Use 'var' keyword when possible", "Use 'var' keyword when initializer explicitly declares type", "Use object or collection initializer when possible", "Similar anonymous type detected nearby", "Convert to lambda expression", "Convert static method invocation to extension method call", "Convert property to auto-property", etc.
- New warnings to comply with best C# 3.0 practices, including "Anonymous method signature is not necessary", "Redundant anonymous type property explicit name", "Redundant braces in collection initializer", "Redundant explicit type in array creation", "Redundant lambda parameter explicit type specification", "Redundant lambda signature parentheses", "Redundant 'partial' modifier on method declaration", and more
- Code completion options are impressively extended. In particular:
- Smart Completion and Symbol Completion are enabled to suggest extension methods, whereas Import Symbol Completion can now be invoked after dot to select from available extension methods and insert required using directives
- Smart Completion in object initializers displays available properties/fields to initialize.
- Smart Completion generates lambda-expression syntax as an alternative for anonymous and named methods
- Refactorings were adapted to C# 3.0 requirements, and a number of new, C#-specific refactorings are now available.
- New templates are implemented, including "from" and "join" for respective LINQ clauses.
Comprehensive Insight into .NET Framework
We have analyzed a great share of .NET Framework Class Library, as well as NUnit Framework, and annotated it through external XML files, using a set of custom attributes from the JetBrains.Annotations namespace, specifically:
- StringFormatMethodAttribute (for methods with format strings as parameters)
- InvokerParameterNameAttribute (for method with string literal arguments that should match one of caller parameters)
- AssertionMethodAttribute (for assertion methods)
- AssertionConditionAttribute (for condition parameters of assertion methods)
- TerminatesProgramAttribute (for methods that terminate control flow)
- CanBeNullAttribute (for values that can be null)
- NotNullAttribute (for values that can not be null)
Having members of the standard class library readily annotated increases the efficiency of code analysis that ReSharper carries out. For example, StringFormatMethodAttribute is used to annotate String.Format-like methods the way that ReSharper checks the number of provided arguments against the structure of format string and warns the user if a necessary argument is missing.
ReSharper 4.0 provides a full-fledged feature called Solution-Wide Analysis, which looks for erroneous C# code in your whole solution on-the-fly, without compiling it first.
Suppose that you changed the visibility of a member from public to internal, assuming that it was only used inside
the current assembly. At this stage, ReSharper finds no errors in the current file. Then, you switch on
Solution-Wide Analysis and the circle indicator in the status bar turns red. You jump to the next error in solution
and you find out that someone used this member from outside of the current assembly. You make necessary amendments,
and that's all! No need to compile, then look for errors, then fix them, and finally repeat the whole process over
and over again.
Initial analysis may take some time to complete while you continue your work, but after it is done, only files that can potentially be affected by recent changes are reanalyzed.
A new, extended reincarnation of what was previously known as Reformat Code. You can now save a myriad of "go-to-next-highlight-then-apply-a-quick-fix" iterations by simply running Code Cleanup!
That's because Code Cleanup is a shortcut for a dozen of ReSharper features — in addition to fine-tuning formatting style to use, you can opt to arrange 'this' qualifier, remove code redundancies, convert properties with backup fields to auto-properties, make fields read-only if possible, optimize using directives, shorten qualified references, update file header, replace explicit types with vars, and revamp your C# code with many more settings. For VB.NET, you can optimize 'import' directives, shorten qualified references, and reformat your code according to a formatting style. Code cleanup works in batch mode, so that you can instantly clean the whole project or even solution.
In addition to the two default modes — Reformat Code and Full Cleanup, you can create custom cleanup presets to fit your individual needs.
Quite obviously, all ReSharper's refactorings support C# 3.0. In addition to that, a number of new, C# 3.0-specific refactorings are introduced:
- Convert Static to Extension Method
- Convert Extension Method to Plain Static
- Convert Property to Auto-Property
- Convert Anonymous to Named Type
Three other brand new refactorings are introduced:
- Inline Method
- Convert Method to Indexer (to Default Property in VB.NET)
- Convert Indexer (Default Property in VB.NET) to Method
Introduce Variable is now implemented in dialogless mode, somewhat similar to live templates. That is, after you
launch the refactoring upon a selection, ReSharper provides two drop-down lists for you to choose a type
(anonymous/named) and a name (a couple of type-dependent options are suggested) for the new variable:
All refactorings that were previously limited to C# 2.0 are now available for Visual Basic 8, including:
- Convert Method to Property
- Convert Property to Method
- Pull Members Up
- Push Members Down
- Extract Interface
- Extract Superclass
- Convert Interface to Abstract Class
- Convert Abstract Class to Interface
- Extract Class from Parameters
- Use Base Type Where Possible
- Replace Constructor with Factory Method
Multiple New Productivity Features
Complete Statement, introduced in ReSharper 4.0, is a feature that inserts necessary syntax elements (braces,
semicolons etc.) and gets you to the position to start the next statement, saving you from excessive juggling with
the caret. As you work, keep in mind the default shortcut for this
feature — Ctrl+Shift+Enter.
Complete Statement (also known as Smart Enter) comes to rescue in numerous scenarios, including auto-closing parentheses, adding semicolons, completing if, while and for statements, and so on.
For example, whenever you declare a new method, Complete Statement comes handy after specifying method parameters:
If you press Ctrl+Shift+Enter at this point, ReSharper will automatically insert a closing
parenthesis, as well as both braces, and put the caret right where you can proceed with writing the method body:
Similarly, you can apply Complete Statement to complete declarations of classes, interfaces, structures, enumerations, delegates, fields, events, access methods and operators, as well as numerous statements and expressions.
CamelHumps in Code Completion
In ReSharper 4.0, all three completion features — Symbol Completion, Smart Completion, and Import Symbol Completion — support CamelHumps, allowing you to complete any symbol by entering only its uppercase characters. For example, instead of the laborsome DecoderReplacementFallback, you can type DRF:
Live Templates Editor & Manager
Live Templates Editor is a rejuvenated set of user interface items for viewing, managing, and editing all three types of templates — Live Templates, Surround With Templates, and File Templates.
Compared to its predecessors in previous versions of ReSharper, it provides a number of valuable advantages:
- Template-related controls are transferred from ReSharper Options to a new dialog box called Templates Manager (pictured above) that you can access from the root level of ReSharper menu. You can dock it in a convenient position, similarly to File Structure or Type Hierarchy.
- A special-purpose dialog box (known as Edit Template in ReSharper 3.x) is abandoned in favor of a separate code
pane (pictured below). This approach is preferable because:
- You can create/edit a custom template and try it in action a lot faster than before, without switching between a dialog box and the code editor,
- Undoing and redoing editing steps is made easier
Click to Enlarge In the Templates Manager, a separate Quick Access List is available for each type of project.
You can group templates by four different sets of criteria:
- By storage, language and category
- By storage and category
- By category and language
- By language and category
- You can now utilize imported Visual Studio's code snippets exactly the way you use ReSharper's templates, including viewing, managing, editing, and applying them.
Recent Edits is a drop-down list similar to existing Go To features that shows files and symbols that you recently modified:
You can instantly navigate to any file or symbol displayed in Recent Edits.
Smoother Interaction with Visual Studio Ecosystem
Visual Studio has an extensive ecosystem that includes Silverlight, .NET Compact Framework, Windows Presentation Foundation, Windows Communication Foundation, Windows Workflow Foundation and other frameworks, plus various add-ins, version control clients, etc.
Previous versions of ReSharper didn't work that well with some ecosystem members. We addressed this problem by testing ReSharper in multiple combinations with them, and making necessary adjustments to make ReSharper work in a friendly, not-intrusive manner, and take their special features into account where possible. That is, overall, the quality of interaction with neighbors in the Visual Studio garden was brought to a new level.
ASP.NET developers have systematically (and rightfully) asked us to draw a little more attention to their share of .NET. Well, here we are — ReSharper 4.0 significantly speeds up analysis of ASP.NET pages, to enable more web developers benefit from the great toolset that ReSharper provides. Previously, you might have had to wait for ReSharper to get out of its meditation at times when processing long .aspx pages, but now that's in the past.
In addition, a number of little benefits are there for you. For instance, Move Type can now be applied to code-behind classes, custom build providers are supported for .resx, and web.config processing is improved in many ways.