Skip to content

Commit 0a5b293

Browse files
committed
Use pattern matching
1 parent 5980b7a commit 0a5b293

File tree

5 files changed

+5
-12
lines changed

5 files changed

+5
-12
lines changed

GitDiffMargin/Core/MarginCore.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,7 @@ private static Brush GetBrush(ResourceDictionary properties)
248248

249249
private void HandleParseComplete(object sender, ParseResultEventArgs e)
250250
{
251-
var diffResult = e as DiffParseResultEventArgs;
252-
if (diffResult == null) return;
253-
254-
CheckBeginInvokeOnUi(() => OnHunksChanged(diffResult.Diff));
251+
if (e is DiffParseResultEventArgs diffResult) CheckBeginInvokeOnUi(() => OnHunksChanged(diffResult.Diff));
255252
}
256253

257254
private void OnHunksChanged(IEnumerable<HunkRangeInfo> hunkRangeInfos)

GitDiffMargin/Git/GitCommands.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ private string AdjustPath(string fullPath)
318318
StringComparison.OrdinalIgnoreCase))
319319
return fullPath;
320320

321-
var solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
322-
if (solution == null)
321+
if (!(_serviceProvider.GetService(typeof(SVsSolution)) is IVsSolution solution))
323322
return fullPath;
324323

325324
if (!ErrorHandler.Succeeded(solution.GetProjectEnum((uint) __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION,

GitDiffMargin/GitDiffMarginCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ private bool TryGetMarginViewModel(out EditorDiffMarginViewModel viewModel)
216216

217217
var textViewHost = _editorAdaptersFactoryService.GetWpfTextViewHost(TextViewAdapter);
218218

219-
var margin = textViewHost?.GetTextViewMargin(EditorDiffMargin.MarginNameConst) as EditorDiffMargin;
220-
if (margin == null)
219+
if (!(textViewHost?.GetTextViewMargin(EditorDiffMargin.MarginNameConst) is EditorDiffMargin margin))
221220
return false;
222221

223222
viewModel = margin.VisualElement.DataContext as EditorDiffMarginViewModel;

GitDiffMargin/View/EditorDiffMarginControl.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ private static void DoubleClick(object sender, EventArgs e)
6262

6363
var button = ClickWaitTimer.Tag as Button;
6464

65-
var editorDiffMarginViewModel = button?.Tag as EditorDiffMarginViewModel;
66-
if (editorDiffMarginViewModel == null) return;
65+
if (!(button?.Tag is EditorDiffMarginViewModel editorDiffMarginViewModel)) return;
6766

6867
var editorDiffViewModel = button.DataContext as EditorDiffViewModel;
6968
editorDiffViewModel?.ShowPopUpCommand.Execute(editorDiffMarginViewModel);

GitDiffMargin/ViewModel/EditorDiffViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ public bool ShowPopup
107107
_showPopup = value;
108108
if (value)
109109
{
110-
var uiShell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell4;
111-
if (uiShell != null)
110+
if (Package.GetGlobalService(typeof(SVsUIShell)) is IVsUIShell4 uiShell)
112111
{
113112
IOleCommandTarget commandTarget =
114113
MarginCore.TextView.Properties.GetProperty<GitDiffMarginCommandHandler>(

0 commit comments

Comments
 (0)