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 dc466fe
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 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));
}

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

0 comments on commit dc466fe

Please sign in to comment.