MergedFile Exercises Manual

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 15

First ExerciseFirst Exercise
Start in the ReSharperWorkshop project. Create the 2 following classes:
Plan
Document
The Plan class should take a name ( string ), some documents ( IEnumerable<Document> ) and a security
classification ( Basic.Support.SecurityClassification ) in it's constructor and expose them as read-only
properties.
One solution could look like this:
Plan.csPlan.cs
using System.Collections.Generic;
using Basic.Support;
namespace ResharperWorkshop
{
public class Plan
{
private readonly string _name;
private readonly IEnumerable<Document> _documents;
private readonly SecurityClassification _securityClassification;
public Plan(
string name,
IEnumerable<Document> documents,
SecurityClassification securityClassification)
{
name = name;
documents = documents;
securityClassification = securityClassification;
}
public string Name
{
get { return _name; }
}
public IEnumerable<Document> Documents
{
get { return _documents; }
}
public SecurityClassification SecurityClassification
{
get { return _securityClassification; }
}
}
}
Document.csDocument.cs
1 / 15
namespace ResharperWorkshop
{
public class Document
{
}
}
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Focus Solution Explorer Ctrl + Alt + L
Locate in Solution Explorer Shift + Alt + L
Open context menu Shift + F10
Focus Code Window Esc
Focus Code Window (more stable) Alt + W, 1
Open menu underlined with Alt + <X>
2 / 15
Go toGo to
Find the shortest sequence of keys to navigate to following items. See example below.
Example - Shor test SequenceExample - Shor test Sequence
The shortest sequence of keys to navigate to
The file BlogEngine.NET/Custom/Themes/Standard/newsletter.html
would be:
Ctrl + Shift + T (Go to file)
n h t (matches nnewsletter.hthtml)
1. The class IActivateHandlers interface in the Rebus namespace
2. The class CommentItem in the BlogEngine.Core.Data.Models namespace
3. The file blog.js file in the Scripts/Auto/ folder
4. The class BlogReader in the BlogEngine.Core.API.BlogML namespace
5. The declaration of the LoginRequired css class in the Content/Auto/Global.css file
6. The Page_Load method in the Account/account.master.cs file
7. The staticContent xmlxml section in the BlogEngine.NET\Web.config file
8. The Application_PreRequestHandlerExecute method in the BlogEngine.NET\Global.asax file
9. The cancelReply method in the Scripts/Auto/blog.js file
10. The Add method of the BlogEngine.Core.Providers.BlogFileSystemProviderCollection class
11. The class that starts with UU in the same namespace as XmlFileSystemProvider
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Go to Type Ctrl + T
Go to File Ctrl + Shift + T
Go to Symbol Shift + Alt + T
Go to Member (current file) Alt + \
Supporting shor tcutsSupporting shor tcuts
Shor tcutShor tcut Key ComboKey Combo
Locate in Solution Explorer Shift + Alt + L
3 / 15
Code AnalysisCode Analysis
Navigate to the ContextClass in the Context solution.
The class contains various ReSharper issues.
HintsHints shown as a short dotted green line beneath the code
SuggestionsSuggestions shown as a green squiggly line beneath the code
DeadDead code shown as faded grey text
WarningsWarnings shown as a blue squiggly line beneath the code
ErrorsErrors shown as red text or red squiggly lines
Do the following
1. Navigate to the 2 errors and fix them. What's wrong?
2. Navigate through the suggestions in the file and see what ReSharper is suggesting. Do you agree?
3. Go through the hints of the file (no shortcut). Does it make sense to apply any of them?
Note: The inspection options can be changed either in the ReSharper options or directly through the Quick fixQuick fix
menu. These can also be shared at solution level through source control, via the Resharper > Manage Options >
Import & Export feature which creates a .DotSettings file.
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Quick fix Alt + Enter
Go to next highlight (error, warning or suggestion) Alt + PageDown
Go to previous highlight (error, warning or suggestion) Alt + PageUp
Go to next error Alt + Shift + PageDown
Go to previous error Alt + Shift + PageUp
4 / 15
Generate CodeGenerate Code
Open the GenerateCode class in the Basic project.
1. From the constructor of GenerateCode call a the non-existant private method like so: Create(name, tags)
2. Use Quick fixQuick fix to create the method
3. From the Create method instantiate a non-existant class like so: new CodeCollection(name, tags)
4. Use Quick fixQuick fix to create the class + constructor
5. Delete the constructor
6. Use Generate codeGenerate code to re-create the constructor
7. Use Quick fixQuick fix to change the name field to be read-only
8. Delete the tags field
9. Generate a property for the tags field
10. Generate equality members for the class depending on the name field
11. Convert the tags property to a Property with backing field
12. Generate delegating methods for the Add method and the Count properties of the tags list
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Quick fix Alt + Enter
Generate code Alt + Insert
Supporting shor tcutsSupporting shor tcuts
Shor tcutShor tcut Key ComboKey Combo
Go to next highlight (error, warning or suggestion) Alt + PageDown
Go to previous highlight (error, warning or suggestion) Alt + PageUp
5 / 15
RenameRename
Navigate to the H class the Basic project.
1. Rename variable e -> lastIndex
2. Rename parameter j -> arrayLength
3. Rename method A -> BuildRandomArray
4. Rename variable d -> index
Figure out what variables (and rename them) should have the following names of the remaining b, c, H, g and
f
random
numbers
swapIndex
temp
ArrayShuffler
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Refactor: Rename Ctrl + R, Ctrl + R
Supporting shor tcutsSupporting shor tcuts
Shor tcutShor tcut Key ComboKey Combo
Refactor this Ctrl + Shift + R
Highlight usages Alt + Shift + F11
6 / 15
Introduce and Inline variablesIntroduce and Inline variables
Open the Variables class in the Basic project.
In the IntroduceVariable method introduce the following variables
1. 0 to firstPage
2. numberOfPages - 1 to lastPage
3. Math.Min(Math.Max(firstPage, page), lastPage) to currentPage
4. currentPage * itemsPerPage to firstItemInPage
5. ((currentPage + 1) * itemsPerPage) - 1 to lastItemInPage
6. new[] { firstItemInPage, lastItemInPage } to itemRange
In the InlineVariable method:
7. Inline all the variables one at a time and watch the effects.
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Refactor this Ctrl + Shift + R
Refactor: Introduce variable Ctrl + R, Ctrl + V
Refactor: Inline variable Ctrl + R, Ctrl + I
7 / 15
Import CompletionImport Completion
Open the ImportCompletion class in the `Basic project.
In the Import method:
1. Instantiate a new DataProcessor() using Impor t completionImpor t completion to import the Basic.Support.Proc
namespace
2. Change the Console.WriteLine call to output list.FirstOrDefault() (extension method) instead of list -
using Impor t completionImpor t completion to import the System.Linq namespace
3. Instantiate a System.Threading.Timeout
4. Instantiate a System.Security.SecureString
In the IntroduceVariableImportCompletionCombo method, find the shortest keysequence for writing the
following statements using Impor t completionImpor t completion followed by Introduce variableIntroduce variable. (see example below)
5. var stringBuilder = new StringBuilder();
6. var dictionary = new HybridDictionary();
7. var collection = new BlockingCollection<ConcurrentQueue<Guid>>();
8. var compressionMode = CompressionMode.Compress;
Example - Impor t/Introduce comboExample - Impor t/Introduce combo
Combining Import completion and Introduce variable.
Shortest key sequence for writing in a file where the System.Text namespace is not imported:
var stringBuilder = new StringBuilder();
would be:
n e w Space
s b u i (matches SS tringBuiBui lder)
Tab (Activate Statement completion/Import completion)
( (completes statement)
Ctrl + R, Ctrl + V (introduce variable)
Enter (picks var in type selector)
Enter (picks stringBuilder in name selector)
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Refactor: Introduce variable Ctrl + R, Ctrl + V
Import completion Tab (when the correct type is selected in the intellisense window)
Refactor this Ctrl + Shift + R
8 / 15
Find Usages and HighlightFind Usages and Highlight
Investigate the following using Find usagesFind usages
1. Where is the ZipDirectory method from the FileSystemUtilities class used?
2. Which .cs file uses the CheckRightsForAdminSettingsPage method in the WebUtils class?
3. From which .cs files can the SaveToDatastore method of the XmlBlogProvider class be invoked? (multiple
Find usagesFind usages)
Navigate to the BlogEngine.Core.Pager class and look at the Reset method (note: there is more than 1 Pager
class)
4. Try to reason about what happens to the page parameter within the constructor
5. Try again with Find usagesFind usages
6. Try again with Highlight usagesHighlight usages
7. What works better? Nothing, Find usagesFind usages or Highlight usagesHighlight usages
Navigate to the RewriteDefault method in the UrlRewrite class. Using Highlight usagesHighlight usages or Find usagesFind usages
figure out
8. What is the last line that the path local variable is used in?
9. What is the last line that the url local variable is used in?
10. What is the last line that the page local variable is used in?
Navigate to the BlogEngine.Core.Blog class
10. Try to reason about who calls the Blog constructor
11. Try again with Highlight usagesHighlight usages
12. Try again with Find usagesFind usages
13. What works better? Nothing, Find usagesFind usages or Highlight usagesHighlight usages
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Find usages Shift + F12
Highlight usages Shift + Alt + F11
Remove Highlight Esc
Supporting shor tcutsSupporting shor tcuts
Shor tcutShor tcut Key ComboKey Combo
Go to next usage Ctrl + Alt + PageDown
Go to previous usage Ctrl + Alt + PageUp
9 / 15
Solution Explorer RefactoringsSolution Explorer Refactorings
Open the Tennis.cs file in the ReSharperWorkshop solution. This file contains an implementation of the
variations of the rules of Tennis in different tournaments.
In the Solution Explorer do the following:
1. Split up the Tennis.cs file using Refactor this - Move types into matching filesRefactor this - Move types into matching files
2. Create Tournament and Models folders using Generate file (Solution Explorer)Generate file (Solution Explorer)
3. Move files into the folder structure shown below using either
Cut / Paste + Refactor this - Adjust namespacesRefactor this - Adjust namespaces
Refactor this - Move to folderRefactor this - Move to folder
4. Which method do you like better?
Tournament
TournamentAustralianOpen.cs
TournamentDouble.cs
TournamentUSOpen.cs
ITournamentRules.cs
Models
TennisGame.cs
TennisSet.cs
TennisMatch.cs
Tip: If you want to start over on this task - simply copy the contents of original.txt into a Tennis.cs file, or
revert the file from source control with git checkout Tennis.cs
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Refactor this Ctrl + Shift + R
Generate item (Solution Explorer) Alt + Insert
Refactor: Move to file/folder Ctrl + R, Ctrl + O
Supporting shor tcutsSupporting shor tcuts
Shor tcutShor tcut Key ComboKey Combo
Locate in Solution Explorer Shift + Alt + L
10 / 15
Move CodeMove Code
Navigate to the OutOfOrderMethods class in the Basic project.
1. Reorder the methods alphabetically using move code.
In the E method:
2. Move the calculation of theOtherNumber into the first if block.
3. Move the try / catch block out of the first if block.
4. Change following expressions to mention variable names before constants:
13 * theNumber should be theNumber * 13
42 == theNumber should be theNumber == 42
null != data should be data != null
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Move code up Ctrl + Shift + Alt + Up
Move code down Ctrl + Shift + Alt + Down
Move code in Ctrl + Shift + Alt + Right
Move code out Ctrl + Shift + Alt + Left
Supporting shor tcutsSupporting shor tcuts
Shor tcutShor tcut Key ComboKey Combo
Go to next class member Alt + Down
Go to previous class member Alt + Up
11 / 15
Navigate HierarchiesNavigate Hierarchies
Navigate to the Navigate method of the NavigateHierachies class.
1. Examine the Type HierarchyType Hierarchy of IEntity
2. What is the difference between Go to implementationGo to implementation and Go to derivedGo to derived on the IPet.Speak method?
3. Where does Go to implementationGo to implementation on IEntity.Id followed by Go to baseGo to base take you? Why?
Navigate to the RebusHierarchyLesson class. Using hierarchy navigation (Go to declarationGo to declaration / Go toGo to
implementationimplementation / Go to baseGo to base / Go to derivedGo to derived) figure out the following:
(Remember that you can consult the Type HierachyType Hierachy)
4. From SimpleHandlerActivator - how can you get to IActivateHandlers
5. From IActivateHandlers - how can you get to WindsorContainerAdapter
6. From WindsorContainerAdapter - how can you get to IContainerAdapter
Without leaving RebusHierarchyLesson figure out the following from the Lesson method.
Hint: Go to derivedGo to derived shows a list of possible navigation targets for whatever's under the caret.
7. Using Type HierachyType Hierachy, which class implementing IActivateHandlers does not implement
IContainerAdapter
8. Number of classes and interfaces implementing IActiveHandlers
9. Out of the these - how many implement the GetHandlerInstancesFor<T>
10. Number of classes and interfaces implementing IHandleMessages<T>
Tip: If you navigate to a file and want to go back to where you were, you can either use Close current fileClose current file or GoGo
back (Visual Studio)back (Visual Studio).
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Go to declaration F12
Go to implementation Ctrl + F12
Go to base Alt + Home
Go to derived Alt + End
Show type hierarchy Ctrl + E, Ctrl + H
Supporting shor tcutsSupporting shor tcuts
12 / 15
Shor tcutShor tcut Key ComboKey Combo
Inspect this Ctrl + Shift + Alt + A
Close current file Ctrl + F4
Go back (Visual Studio) Ctrl + - (minus symbol above P)
13 / 15
Inspect ThisInspect This
Navigate to the Inspector class in the Basic project.
Tip: Remember that the inspection window can be docked and that Show Preview on the Right is useful.
1. Explore the value destination of importantValue in the Main method. Where does it end up?
2. Explore the value origin of the value variable in the Main method. What values are printed?
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Inspect this Ctrl + Shift + Alt + A
14 / 15
First Exercise RevisitedFirst Exercise Revisited
Repeat the first exercise, but try to incorporate the things you've learned in the previous exercises. Below you'll find
a list of the shortcuts that might be helpful for faster flows.
ProblemProblem
Start in the ReSharperWorkshop project. Create the 2 following classes:
Plan
Document
The Plan class should take a name ( string ), some documents ( IEnumerable<Document> ) and a security
classification ( Basic.Support.SecurityClassification ) in it's constructor and expose them as read-only
properties.
Primary shortcutsPrimary shortcuts
Shor tcutShor tcut Key ComboKey Combo
Quick fix Alt + Enter
All fixes Ctrl + .
Generate file (Solution Explorer) Alt + Ins
Generate code Alt + Ins
Import completion Tab
Go to next suggestion Alt + PageDown
Go to previous suggestion Alt + PageUp
Go to next error Shift + Alt + PageDown
Go to previous error Shift + Alt + PageUp
15 / 15

Navigation menu