Skip to content

Commit

Permalink
Use pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentkempe committed Aug 25, 2018
1 parent 5980b7a commit 0a5b293
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
5 changes: 1 addition & 4 deletions GitDiffMargin/Core/MarginCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ private static Brush GetBrush(ResourceDictionary properties)

private void HandleParseComplete(object sender, ParseResultEventArgs e)
{
var diffResult = e as DiffParseResultEventArgs;
if (diffResult == null) return;

CheckBeginInvokeOnUi(() => OnHunksChanged(diffResult.Diff));
if (e is DiffParseResultEventArgs diffResult) CheckBeginInvokeOnUi(() => OnHunksChanged(diffResult.Diff));

This comment has been minimized.

Copy link
@sharwell

sharwell Aug 25, 2018

Collaborator

💡 this would be more readable if it didn't leave the block all on one line

}

private void OnHunksChanged(IEnumerable<HunkRangeInfo> hunkRangeInfos)
Expand Down
3 changes: 1 addition & 2 deletions GitDiffMargin/Git/GitCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ private string AdjustPath(string fullPath)
StringComparison.OrdinalIgnoreCase))
return fullPath;

var solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
if (solution == null)
if (!(_serviceProvider.GetService(typeof(SVsSolution)) is IVsSolution solution))
return fullPath;

if (!ErrorHandler.Succeeded(solution.GetProjectEnum((uint) __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION,
Expand Down
3 changes: 1 addition & 2 deletions GitDiffMargin/GitDiffMarginCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ private bool TryGetMarginViewModel(out EditorDiffMarginViewModel viewModel)

var textViewHost = _editorAdaptersFactoryService.GetWpfTextViewHost(TextViewAdapter);

var margin = textViewHost?.GetTextViewMargin(EditorDiffMargin.MarginNameConst) as EditorDiffMargin;
if (margin == null)
if (!(textViewHost?.GetTextViewMargin(EditorDiffMargin.MarginNameConst) is EditorDiffMargin margin))
return false;

viewModel = margin.VisualElement.DataContext as EditorDiffMarginViewModel;
Expand Down
3 changes: 1 addition & 2 deletions GitDiffMargin/View/EditorDiffMarginControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ private static void DoubleClick(object sender, EventArgs e)

var button = ClickWaitTimer.Tag as Button;

var editorDiffMarginViewModel = button?.Tag as EditorDiffMarginViewModel;
if (editorDiffMarginViewModel == null) return;
if (!(button?.Tag is EditorDiffMarginViewModel editorDiffMarginViewModel)) return;

var editorDiffViewModel = button.DataContext as EditorDiffViewModel;
editorDiffViewModel?.ShowPopUpCommand.Execute(editorDiffMarginViewModel);
Expand Down
3 changes: 1 addition & 2 deletions GitDiffMargin/ViewModel/EditorDiffViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public bool ShowPopup
_showPopup = value;
if (value)
{
var uiShell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell4;
if (uiShell != null)
if (Package.GetGlobalService(typeof(SVsUIShell)) is IVsUIShell4 uiShell)
{
IOleCommandTarget commandTarget =
MarginCore.TextView.Properties.GetProperty<GitDiffMarginCommandHandler>(
Expand Down

0 comments on commit 0a5b293

Please sign in to comment.