ReSharper Presentation for NUGs

Post on 26-Jun-2015

3.212 views 1 download

Tags:

description

ReSharper presentation that can be given by .Net user group leaders.

Transcript of ReSharper Presentation for NUGs

1

Introducing

The most intelligent plug-in for

Visual Studio

2

ReSharper in a Nutshell

Coding productivity tool for Visual Studio users

Supports C#, VB.NET, XML, XAML, ASP.NET,

HTML/CSS/JavaScript, build scripts

Continuous code quality analysis: error detection and

quick-fixes

Navigation, coding assistance, code generation, unit

test integration…

3

Visual Studio with ReSharper

4

Syntax Highlighting

R# extends VS highlighting:

For fields, variables, constants, methods, operators, types, etc.

In C# and VB.NET:

5

Code Analysis

R# provides on-the-fly code quality analysis.

4 categories of analysis results:

Errors

Warnings

Suggestions

Hints

6

Code Inspections Wiki

Some suggestions are very technical, so ReSharper offers explanations:

Clicking on the “Why is ReSharper

Suggesting This” item opens up

the corresponding page in the

Code Inspection Wiki:

7

Marker Bar

Marker Bar is a sidebar to the right-

hand side of the text editor.

MB represents all R# highlights in

file (warnings, errors, suggestions,

to-do items and search results):

Status Indicator shows the

overall status of the current file:

It changes color if file contains

errors or warnings:

File contains compilation errors

File has warnings but no errors

File doesn't contain errors or

warnings

8

Solution-Wide Analysis

ReSharper can analyze your whole solution for errors

To turn on, double-click the bottom left icon in Visual Studio:

Circle is green if there are no errors, red otherwise

Double-click the circle to see a list of issues

9

Find Code Issues

ReSharper can locate all issues (errors

and warnings) in the current project or

the whole solution

To get a list of issues, use the menu item

ReSharper | Inspect | Code Issues in

Solution/Current Project

ReSharper presents a tree of all issues

found, with various grouping options:

ReSharper can also help find issues

similar to the one that has just been

encountered:

Similar issues can be searched at

different (including Custom) scopes:

10

Quick-Fixes

Quick-fixes make you code free of errors and smells

Available for most errors, warnings, and suggestions that R# displays

Bulbs used to indicate availability

Red bulb indicates an error

Yellow bulb indicates a warning

To display the list of available quick-fixes, press Alt+Enter:

Hundreds of quick-fixes to perform multiple fixes

11

Context Actions

Context actions are "mini-refactorings" intended for optional code

transformations in a certain context. Examples:

Modifying the structure of conditional statements

Joining local variable declaration and assignment

Iterating collections with foreach statements

Context actions are available for C#, VB.NET and XML

Pencil icon to the left a code line means CAs are available

12

Code Completion

R# complements native VS IntelliSense with 3 types of code completion:

Symbol Completion

Smart Completion

Import Symbol Completion

Enhancements compared to Visual Studio include: Immediate members are highlighted (vs inherited members)All overloads displayed in a pop-up, you can scroll between them Icons for parameters and local vars to distinguish them from fieldsCompletion list is narrowed down to match user inputCamelHumps: complete a long type name by typing “drfb"

instead of "DecoderReplacementFallbackBuffer"

13

Symbol Completion

Suggesting type-based variable names:

Suggesting members of a class:

Suggesting visible types:

14

Symbol Completion (cont.)

Suggesting C# keywords:

Symbol completion using CamelHumps:

Completing names of symbols in build scripts:

15

Smart Completion

Smart Code Completion (Ctrl+Alt+Space):

Filters the list of types, methods, and variables to match the

expected type of an expression

If several return types are possible, detects the most recently used

symbol of an applicable type and focuses it in the lookup list

Suggests creating anonymous delegates, lambda expressions, and

regular methods, as well as local variables for out parameters

In object initializers, suggests fields/properties that were not yet

assigned a value

16

Smart Completion (cont.)

In object initializers:

In lambda expressions:

Creating a local variable in place of an out parameter:

17

Import Completion

In C# for extension methods:

In C# using CamelHumps:

In ASP.NET:

18

Complete Statement

Complete Statement (Ctrl+Shift+Enter):

Inserts necessary syntax elements (braces, semicolons etc.)

and gets you in position to start the next statement

Is helpful in auto-closing parentheses, adding semicolons,

completing if, while and for statements etc.

Available for type members, statements, and expressions

Nested method invocation: before Complete Statement:

Nested method invocation: after Complete Statement:

19

Parameter Info

When you call a method, Parameter Info (Ctrl+Shift+Space):

Automatically shows all available signatures and parameters with

relevant documentation

Grays out inapplicable signatures as you add new arguments

20

Quick Documentation

Quick Documentation (Ctrl+Shift+F1):

Shows a pop-up with available doc for any documented symbol

Does so in the text editor, in any ReSharper tool window, or within

documentation comments

Provides hyperlinks to detailed information and documentation for

related symbols

21

Namespace Import Pop-Ups

When referencing a non-imported type, ReSharper helps promptly add it

to the list of namespace import directives

Adding a using directive this way doesn't interrupt your coding session

When pasting code from another part of your application, ReSharper will

offer to import all required types:

22

Live Templates

Live templates are predefined code fragments (expressions, constructs,

classes, methods etc.) that can be quickly inserted into code

By default, ReSharper 5 provides more than 20 live templates for C#, 17

for VB.NET, 6 for ASP.NET and 3 for XML

Iterating through collections

Creating assertion methods

Creating new arrays

Outputting values

Coding LINQ queries

Generating auto-properties

23

Surround Templates

Surround templates let you select code and surround it with code from a

live template (e.g., with a try-catch block)

Select the text to surround and press Ctrl+E,Ctrl+U to open up a list of

surround templates

Use keyboard shortcuts to select

one of the templates

Choose More… to see all available

templates and select which ones

appear in the quicklist

24

Structural Search and Replace (SSR)

SSR lets you create your own patterns to search for code smells, legacy

code constructs, etc.

Open the patterns catalog in ReSharper | Tools | Patterns Catalog

Define your own patterns and what to replace them with

ReSharper will highlight instances where pattern matches, and offers the

quick-fix for replacement:

25

Navigate To

Navigate To (Alt+`): context menu that shows all navigation options

available at the current caret position:

26

Navigate To (cont.)

Specifically, you can navigate to:

Declaration

Implementation

Base symbols

Derived symbols

Types of symbol

Usages of symbol

Control flow target

Function exit(s)

Overriding members

Conflicting declarations

Member overloads

Related files

To-do explorer

Test explorer

Object browser

Metadata view

Sources from symbol files

Decompiled sources

27

Navigate To (cont.)You can navigate to source files

located outside your solutionE.g., .Net Framework

Source Code

Simply select navigation to external symbol

ReSharper downloads PDBs from the source server…

And displays the source file:

28

Call & Value Tracking

ReSharper lets you can track…

Incoming and outgoing

calls to a method (method calls

resulting in this call being

made, or calls resulting from

the call of this method)

Origin and destination

of values (who provides

the value and where it goes)

Menu items are available

under ReSharper | Inspect

Inspections indicate all affected

locations up/down the call chain:

29

Generate

Generate drop-down menu (Alt+Ins) helps:

Implement and override members

Generate properties

Generate type constructors

Generate delegating members

Generate equality members

Generate formatting members

30

Refactor This

ReSharper provides 40+ solution-wide refactorings.

Refactor This (Ctrl+Shift+R): context menu to view and call refactorings

available at a certain code position:

31

Find Usages

Find Usages (Alt+F7) quickly locates usages of a symbol solution-wide

In mixed-language solutions, finds usages multiple languages

Search results are displayed in the Find Results window:

32

Navigation & Search

3 groups of "go to" navigation commands.

Group 1: Navigate from anywhere. Commands in this group open in pop-

up windows, support CamelHumps and wildcards (* for 0 or more

characters, ? for 1 or more characters):

Go to Symbol

Go to Type

Go to File Member

Go to File

33

Navigation & Search (cont.)

Group 2: Navigate from occurrence of a specific symbol. Navigate from

Here is used as a shortcut for these commands:

Go to Declaration

Go to Type Declaration

Go to Base

Go to Inheritor

Go to Usages

34

Navigation & Search (cont.)

Group 3: Navigate from anywhere within a type:

Go to Next/Previous Member

Go to Containing Declaration

+ Go to Last Edit Location navigates to the point of the most recent code

modification

35

View Recent Edits

Recent Edits (Ctrl+Shift+,) is a pop-up window similar to Recent Files

that shows files and symbols that you have recently modified:

36

Locate in Solution Explorer

Locate in Solution Explorer (Shift+Alt+L) highlights the currently opened

file in Solution Explorer and auto-scrolls to its entry:

It is especially useful in large solutions, or when screen area limitations

forces you to shrink the Solution Explorer window to the limit

37

File Structure

File Structure window (Ctrl+Alt+F) shows members or elements that the

current code or markup file contains, and lets you navigate directly to

their declarations:

38

Type Hierarchy

Type Hierarchy (Ctrl+Alt+H at a type usage) shows the inheritance

hierarchy of a specified type; its base types and inheritors:

39

ReSharper Refactorings

The richest set of automated solution-wide refactorings for C# and VB

available in Visual Studio ecosystem (40+ refactorings as of R# 5)

200+ context actions = “mini-refactorings”

Each code refactoring analyzes the entire scope of the code selection to

which it is applied (as wide as whole solution), including cross-language

code

40

ReSharper Refactorings (cont.)

Refactorings can be invoked with:

Individual keyboard shortcuts (whenever available)

Refactor This (Ctrl+Shift+R) context menu that lists contextually

available refactorings

ReSharper | Refactor menu

Some refactorings can be triggered with context actions (watch the

yellow bulb)

If a conflict is detected that prevents running a refactoring, a special

warning screen is shown, and the user can modify the code to resolve

the issue

41

In-Place Refactorings

ReSharper can detect when changes in code lead to a refactoring. In

this case, the refactoring is offered in-place via a context action.

For example, when a variable is renamed, the Rename refactoring is

offered in-place:

42

Code Cleanup

Code Cleanup (Ctrl+E,C) combines customizable code formatting in any

scope with a set of other useful actions, including:

Removing code redundancies (C#)

Optimizing namespace import directives (C#, VB.NET)

Reordering type members (C#)

Migrating to C# 3.0/4.0

For example, you can simply run Code Cleanup to remove code

redundancies instead of navigating between individual warnings and

fixing them one-by-one

43

Unit Testing

ReSharper recognizes NUnit

tests and lets you run or debug

them

in Visual Studio

You can run or debug:

A single unit test

All tests in a test class

All tests in a project

All tests in a solution

ReSharper provides two tool

windows – Unit Test Explorer and

Unit Test Sessions – to view, run

and manage unit tests

44

Support for ASP.NET MVC

Navigation to/from actions and controllers

Creation of new controllers and actions from usage

Special syntax highlighting for ASP.NET MVC method calls and parameters

Dedicated code completion to help you reference actions and controllers in string literals:

45

Support for HTML/CSS/JavaScript

ReSharper comes with comprehensive support for HTML, CSS and JavaScript, including

Inspections

Refactorings

Navigation

And a lot more…

46

LocalizationLocalizable strings are highlighted

and context actions are available for moving them to resources

This functionality is available not just in code, but also in web apps and arbitrary HTML strings

Refactorings (move, rename, inline, safe delete) are available on resources

A special version of the File Structure window is available for viewing resource files

Resource-specific code inspections are available

Find Usages works naturally on resources

Navigation items “Go to Inheritor” and “Go to Base” help you move between culture-neutral and culture-specific resource files

47

Color Assistance

ReSharper helps identify colors in code (C#, VB) and markup (XAML, CSS) by using the color to underline the identifier:

Completion menus are stylizedto show colors:

CSS support also comes with a dedicated color palette:

48

Decompiler

No source? No problem! ReSharper comes with a built-in decompiler*

*Also available separately as dotPeek, see http://jetbrains.com/decompiler

49

Optimize References

ReSharper can show you details of how project references are used in your project:

Alternatively, you can just quickly remove all unused ones:

50

ReSharper Plugins

Some of ReSharper plug-ins include:

Gallio: support for MbUnit, MSTest, NBehave, NUnit and xUnit.Net

Agent Smith: validation of XML comments and naming

conventions; spell checking in XML comments, string literals,

identifiers and resources

Agent Johnson: miscellaneous tools and refactorings

StyleCop for ReSharper: support for Microsoft StyleCop

51

Summary: Most Important Shortcuts

Alt+Enter: display the list of available quick-fixes and/or context actions

Alt+Ins: show code generation options

Alt+` (Navigate To): show available navigation options

Ctrl+Shift+R (Refactor This): show available refactorings

Ctrl+Space (Symbol Completion), Ctrl+Alt+Space (Smart Completion),

Shift+Alt+Space (Import Symbol Completion)

Ctrl+E,C (Code Cleanup)