From fc55704f83db3d461a060abb139c70832d3cd5e7 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Mon, 31 Jul 2017 16:00:02 -0700 Subject: [PATCH] Inline out variable parameters --- PSReadLine/BasicEditing.cs | 12 ++++------- PSReadLine/Completion.cs | 23 ++++++-------------- PSReadLine/ConsoleKeyChordConverter.cs | 9 +++----- PSReadLine/ConsoleLib.cs | 9 +++----- PSReadLine/History.cs | 24 +++++++-------------- PSReadLine/KeyBindings.cs | 6 ++---- PSReadLine/KillYank.cs | 16 +++++--------- PSReadLine/Movement.cs | 30 +++++++++----------------- PSReadLine/Movement.vi.cs | 18 ++++++---------- PSReadLine/Options.cs | 6 ++---- PSReadLine/ReadLine.cs | 15 +++++-------- PSReadLine/ReadLine.vi.cs | 12 ++++------- PSReadLine/Render.cs | 12 ++++------- PSReadLine/YankPaste.vi.cs | 24 +++++++-------------- 14 files changed, 71 insertions(+), 145 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index 069c092..46fc3b6 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -35,8 +35,7 @@ namespace Microsoft.PowerShell var toInsert = new string(key.Value.KeyChar, count); if (_singleton._visualSelectionCommandCount > 0) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); Replace(start, length, toInsert); } else @@ -49,8 +48,7 @@ namespace Microsoft.PowerShell if (_singleton._visualSelectionCommandCount > 0) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); Replace(start, length, new string(key.Value.KeyChar, 1)); } else @@ -155,8 +153,7 @@ namespace Microsoft.PowerShell { if (_singleton._visualSelectionCommandCount > 0) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); Delete(start, length); return; } @@ -187,8 +184,7 @@ namespace Microsoft.PowerShell if (_visualSelectionCommandCount > 0) { - int start, length; - GetRegion(out start, out length); + GetRegion(out var start, out var length); Delete(start, length); return; } diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index 1f4da0e..87ce9f9 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -249,8 +249,7 @@ namespace Microsoft.PowerShell return; } - bool ambiguous; - var replacementText = GetUnambiguousPrefix(completions.CompletionMatches, ambiguous: out ambiguous); + var replacementText = GetUnambiguousPrefix(completions.CompletionMatches, out var ambiguous); if (replacementText.Length > 0) { @@ -537,8 +536,7 @@ namespace Microsoft.PowerShell private bool IsDoneWithCompletions(CompletionResult currentCompletion, ConsoleKeyInfo nextKey) { if (nextKey == Keys.Space || nextKey == Keys.Enter) return true; - ConsoleKeyInfo[] doneKeys; - if (doneCompletionKeys.TryGetValue(currentCompletion.ResultType, out doneKeys)) + if (doneCompletionKeys.TryGetValue(currentCompletion.ResultType, out var doneKeys)) { return doneKeys.Contains(nextKey); } @@ -563,12 +561,8 @@ namespace Microsoft.PowerShell var matches = completions.CompletionMatches; - int menuColumnWidth; - int displayRows; - int selectedItem; var menuBuffer = CreateCompletionMenu(matches, _console, Options.ShowToolTips, - "", out selectedItem, - out menuColumnWidth, out displayRows); + "", out var selectedItem, out var menuColumnWidth, out var displayRows); if (menuSelect) { @@ -593,8 +587,7 @@ namespace Microsoft.PowerShell int savedUserMark = _mark; _visualSelectionCommandCount++; - bool ambiguous; - var userCompletionText = GetUnambiguousPrefix(matches, ambiguous: out ambiguous); + var userCompletionText = GetUnambiguousPrefix(matches, out var ambiguous); // remove possible first quote if (userCompletionText.Length > 0 && ( IsSingleQuote(userCompletionText[0]) @@ -687,7 +680,7 @@ namespace Microsoft.PowerShell else if (nextKey == Keys.Tab) { // Search for possible unAmbiguous common prefix. ... - string unAmbiguousText = GetUnambiguousPrefix(matches, ambiguous: out ambiguous); + string unAmbiguousText = GetUnambiguousPrefix(matches, out ambiguous); int userComplPos = unAmbiguousText.IndexOf(userCompletionText, StringComparison.OrdinalIgnoreCase); // ... If found - advance IncrementalCompletion ... if (unAmbiguousText.Length > 0 && userComplPos >= 0 && unAmbiguousText.Length > (userComplPos + userCompletionText.Length)) @@ -782,8 +775,7 @@ namespace Microsoft.PowerShell matches = tmpMatches; previousItem = -1; menuBuffer = CreateCompletionMenu(matches, _console, Options.ShowToolTips, - selectedCompletionText, out selectedItem, - out menuColumnWidth, out displayRows); + selectedCompletionText, out selectedItem, out menuColumnWidth, out displayRows); } else { @@ -804,8 +796,7 @@ namespace Microsoft.PowerShell prependNextKey = true; // without this branch experience doesnt look naturally - KeyHandler handler; - if (_dispatchTable.TryGetValue(nextKey, out handler) && + if (_dispatchTable.TryGetValue(nextKey, out var handler) && ( handler.Action == CopyOrCancelLine || handler.Action == Cut || diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index 1cd3082..b0cb615 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -81,8 +81,7 @@ namespace Microsoft.PowerShell // Enum.TryParse accepts arbitrary integers. We shouldn't, // but single digits need to map to the correct key, e.g. // ConsoleKey.D1 - long tokenAsLong; - if (long.TryParse(token, out tokenAsLong)) + if (long.TryParse(token, out var tokenAsLong)) { if (tokenAsLong >= 0 && tokenAsLong <= 9) { @@ -99,8 +98,7 @@ namespace Microsoft.PowerShell // doesn't map to ConsoleKey so convert to virtual key from char if (!valid && token.Length == 1) { - string failReason; - valid = TryParseCharLiteral(token[0], ref modifiers, ref key, out failReason); + valid = TryParseCharLiteral(token[0], ref modifiers, ref key, out var failReason); if (!valid) { @@ -116,7 +114,6 @@ namespace Microsoft.PowerShell else { // now, parse modifier(s) - ConsoleModifiers modifier; // courtesy translation if (token == "ctrl") @@ -124,7 +121,7 @@ namespace Microsoft.PowerShell token = "control"; } - if (Enum.TryParse(token, ignoreCase: true, result: out modifier)) + if (Enum.TryParse(token, ignoreCase: true, result: out var modifier)) { // modifier already set? if ((modifiers & modifier) != 0) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 599fb34..74ac605 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -459,8 +459,7 @@ namespace Microsoft.PowerShell.Internal public uint GetConsoleInputMode() { var handle = _inputHandle.Value.DangerousGetHandle(); - uint result; - NativeMethods.GetConsoleMode(handle, out result); + NativeMethods.GetConsoleMode(handle, out var result); return result; } @@ -770,8 +769,7 @@ namespace Microsoft.PowerShell.Internal } _istmInitialized = true; } - int width; - result = NativeMethods.GetCharWidth32(_hDC, (uint)c, (uint)c, out width); + result = NativeMethods.GetCharWidth32(_hDC, (uint)c, (uint)c, out var width); if (!result) { return 1; @@ -822,8 +820,7 @@ namespace Microsoft.PowerShell.Internal return true; // Char device - if GetConsoleMode succeeds, we are NOT redirected. - uint mode; - return !NativeMethods.GetConsoleMode(handle, out mode); + return !NativeMethods.GetConsoleMode(handle, out var mode); } } diff --git a/PSReadLine/History.cs b/PSReadLine/History.cs index 556e85c..e87126c 100644 --- a/PSReadLine/History.cs +++ b/PSReadLine/History.cs @@ -375,8 +375,7 @@ namespace Microsoft.PowerShell if (Options.HistoryNoDuplicates) { var line = _history[newHistoryIndex]._line; - int index; - if (!_hashedHistory.TryGetValue(line, out index)) + if (!_hashedHistory.TryGetValue(line, out var index)) { _hashedHistory.Add(line, newHistoryIndex); --count; @@ -404,8 +403,7 @@ namespace Microsoft.PowerShell /// public static void PreviousHistory(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, -1); + TryGetArgAsInt(arg, out var numericArg, -1); if (numericArg > 0) { numericArg = -numericArg; @@ -420,8 +418,7 @@ namespace Microsoft.PowerShell /// public static void NextHistory(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, +1); + TryGetArgAsInt(arg, out var numericArg, +1); _singleton.SaveCurrentLine(); _singleton.HistoryRecall(numericArg); @@ -468,8 +465,7 @@ namespace Microsoft.PowerShell { if (Options.HistoryNoDuplicates) { - int index; - if (!_hashedHistory.TryGetValue(line, out index)) + if (!_hashedHistory.TryGetValue(line, out var index)) { _hashedHistory.Add(line, newHistoryIndex); --count; @@ -518,8 +514,7 @@ namespace Microsoft.PowerShell /// public static void HistorySearchBackward(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, -1); + TryGetArgAsInt(arg, out var numericArg, -1); if (numericArg > 0) { numericArg = -numericArg; @@ -535,8 +530,7 @@ namespace Microsoft.PowerShell /// public static void HistorySearchForward(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, +1); + TryGetArgAsInt(arg, out var numericArg, +1); _singleton.SaveCurrentLine(); _singleton.HistorySearch(numericArg); @@ -553,8 +547,7 @@ namespace Microsoft.PowerShell { if (Options.HistoryNoDuplicates) { - int index; - if (!_hashedHistory.TryGetValue(line, out index)) + if (!_hashedHistory.TryGetValue(line, out var index)) { _hashedHistory.Add(line, searchFromPoint); } @@ -601,8 +594,7 @@ namespace Microsoft.PowerShell while (true) { var key = ReadKey(); - KeyHandler handler; - _dispatchTable.TryGetValue(key, out handler); + _dispatchTable.TryGetValue(key, out var handler); var function = handler != null ? handler.Action : null; if (function == ReverseSearchHistory) { diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 332e15b..7284bd8 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -329,16 +329,14 @@ namespace Microsoft.PowerShell _singleton._statusLinePrompt = "what-is-key: "; _singleton.Render(); var toLookup = ReadKey(); - KeyHandler keyHandler; var buffer = new StringBuilder(); - _singleton._dispatchTable.TryGetValue(toLookup, out keyHandler); + _singleton._dispatchTable.TryGetValue(toLookup, out var keyHandler); buffer.Append(toLookup.ToGestureString()); if (keyHandler != null) { if (keyHandler.BriefDescription == "ChordFirstKey") { - Dictionary secondKeyDispatchTable; - if (_singleton._chordDispatchTable.TryGetValue(toLookup, out secondKeyDispatchTable)) + if (_singleton._chordDispatchTable.TryGetValue(toLookup, out var secondKeyDispatchTable)) { toLookup = ReadKey(); secondKeyDispatchTable.TryGetValue(toLookup, out keyHandler); diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index 5b8da82..e2a7569 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -193,8 +193,7 @@ namespace Microsoft.PowerShell /// public static void KillRegion(ConsoleKeyInfo? key = null, object arg = null) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); _singleton.Kill(start, length, true); } @@ -251,10 +250,8 @@ namespace Microsoft.PowerShell return; } - Token[] tokens; - ParseError[] errors; var buffer = _history[yankLastArgState.historyIndex]; - Parser.ParseInput(buffer._line, out tokens, out errors); + Parser.ParseInput(buffer._line, out var tokens, out var errors); int arg = (yankLastArgState.argument < 0) ? tokens.Length + yankLastArgState.argument - 1 @@ -470,8 +467,7 @@ namespace Microsoft.PowerShell textToPaste = textToPaste.Replace("\r", ""); if (_singleton._visualSelectionCommandCount > 0) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); Replace(start, length, textToPaste); } else @@ -489,8 +485,7 @@ namespace Microsoft.PowerShell string textToSet; if (_singleton._visualSelectionCommandCount > 0) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); textToSet = _singleton._buffer.ToString(start, length); } else @@ -525,8 +520,7 @@ namespace Microsoft.PowerShell { if (_singleton._visualSelectionCommandCount > 0) { - int start, length; - _singleton.GetRegion(out start, out length); + _singleton.GetRegion(out var start, out var length); ExecuteOnSTAThread(() => Clipboard.SetText(_singleton._buffer.ToString(start, length))); Delete(start, length); } diff --git a/PSReadLine/Movement.cs b/PSReadLine/Movement.cs index 194a032..2800b88 100644 --- a/PSReadLine/Movement.cs +++ b/PSReadLine/Movement.cs @@ -76,8 +76,7 @@ namespace Microsoft.PowerShell /// public static void ForwardChar(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (TryGetArgAsInt(arg, out numericArg, 1)) + if (TryGetArgAsInt(arg, out var numericArg, 1)) { SetCursorPosition(_singleton._current + numericArg); } @@ -89,8 +88,7 @@ namespace Microsoft.PowerShell /// public static void BackwardChar(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (TryGetArgAsInt(arg, out numericArg, 1)) + if (TryGetArgAsInt(arg, out var numericArg, 1)) { SetCursorPosition(_singleton._current - numericArg); } @@ -139,8 +137,7 @@ namespace Microsoft.PowerShell /// public static void PreviousLine(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (TryGetArgAsInt(arg, out numericArg, 1)) + if (TryGetArgAsInt(arg, out var numericArg, 1)) { _singleton.MoveToLine(-numericArg); } @@ -151,8 +148,7 @@ namespace Microsoft.PowerShell /// public static void NextLine(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (TryGetArgAsInt(arg, out numericArg, 1)) + if (TryGetArgAsInt(arg, out var numericArg, 1)) { _singleton.MoveToLine(numericArg); } @@ -164,8 +160,7 @@ namespace Microsoft.PowerShell /// public static void NextWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -190,8 +185,7 @@ namespace Microsoft.PowerShell /// public static void ShellNextWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -222,8 +216,7 @@ namespace Microsoft.PowerShell /// public static void ForwardWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -248,8 +241,7 @@ namespace Microsoft.PowerShell /// public static void ShellForwardWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -290,8 +282,7 @@ namespace Microsoft.PowerShell /// public static void BackwardWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -323,8 +314,7 @@ namespace Microsoft.PowerShell /// public static void ShellBackwardWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } diff --git a/PSReadLine/Movement.vi.cs b/PSReadLine/Movement.vi.cs index 57a86fc..548fc8b 100644 --- a/PSReadLine/Movement.vi.cs +++ b/PSReadLine/Movement.vi.cs @@ -17,8 +17,7 @@ namespace Microsoft.PowerShell /// public static void ViNextWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -48,8 +47,7 @@ namespace Microsoft.PowerShell /// public static void ViBackwardWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -73,8 +71,7 @@ namespace Microsoft.PowerShell /// public static void ViBackwardGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -93,8 +90,7 @@ namespace Microsoft.PowerShell /// public static void ViNextGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -111,8 +107,7 @@ namespace Microsoft.PowerShell public static void ViEndOfGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -133,8 +128,7 @@ namespace Microsoft.PowerShell public static void ViEndOfPreviousGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } diff --git a/PSReadLine/Options.cs b/PSReadLine/Options.cs index 4382f9a..e3502fa 100644 --- a/PSReadLine/Options.cs +++ b/PSReadLine/Options.cs @@ -190,8 +190,7 @@ namespace Microsoft.PowerShell else { _dispatchTable[chord[0]] = MakeKeyHandler(Chord, "ChordFirstKey"); - Dictionary secondDispatchTable; - if (!_chordDispatchTable.TryGetValue(chord[0], out secondDispatchTable)) + if (!_chordDispatchTable.TryGetValue(chord[0], out var secondDispatchTable)) { secondDispatchTable = new Dictionary(); _chordDispatchTable[chord[0]] = secondDispatchTable; @@ -212,8 +211,7 @@ namespace Microsoft.PowerShell } else { - Dictionary secondDispatchTable; - if (_chordDispatchTable.TryGetValue(chord[0], out secondDispatchTable)) + if (_chordDispatchTable.TryGetValue(chord[0], out var secondDispatchTable)) { secondDispatchTable.Remove(chord[1]); if (secondDispatchTable.Count == 0) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 50333f6..ae2c5a8 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -332,8 +332,7 @@ namespace Microsoft.PowerShell sb.Append(' '); sb.Append(_lastNKeys[i].ToGestureString()); - KeyHandler handler; - if (_singleton._dispatchTable.TryGetValue(_lastNKeys[i], out handler) && + if (_singleton._dispatchTable.TryGetValue(_lastNKeys[i], out var handler) && "AcceptLine".Equals(handler.BriefDescription, StringComparison.OrdinalIgnoreCase)) { // Make it a little easier to see the keys @@ -456,8 +455,7 @@ namespace Microsoft.PowerShell void ProcessOneKey(ConsoleKeyInfo key, Dictionary dispatchTable, bool ignoreIfNoAction, object arg) { - KeyHandler handler; - if (!dispatchTable.TryGetValue(key, out handler)) + if (!dispatchTable.TryGetValue(key, out var handler)) { // If we see a control character where Ctrl wasn't used but shift was, treat that like // shift hadn't be pressed. This cleanly allows Shift+Backspace without adding a key binding. @@ -670,8 +668,7 @@ namespace Microsoft.PowerShell throw new ArgumentNullException("key"); } - Dictionary secondKeyDispatchTable; - if (_singleton._chordDispatchTable.TryGetValue(key.Value, out secondKeyDispatchTable)) + if (_singleton._chordDispatchTable.TryGetValue(key.Value, out var secondKeyDispatchTable)) { var secondKey = ReadKey(); _singleton.ProcessOneKey(secondKey, secondKeyDispatchTable, ignoreIfNoAction: true, arg: arg); @@ -758,8 +755,7 @@ namespace Microsoft.PowerShell while (true) { var nextKey = ReadKey(); - KeyHandler handler; - if (_singleton._dispatchTable.TryGetValue(nextKey, out handler)) + if (_singleton._dispatchTable.TryGetValue(nextKey, out var handler)) { if (handler.Action == DigitArgument) { @@ -799,8 +795,7 @@ namespace Microsoft.PowerShell } } - int intArg; - if (int.TryParse(argBuffer.ToString(), out intArg)) + if (int.TryParse(argBuffer.ToString(), out var intArg)) { _singleton.ProcessOneKey(nextKey, _singleton._dispatchTable, ignoreIfNoAction: false, arg: intArg); } diff --git a/PSReadLine/ReadLine.vi.cs b/PSReadLine/ReadLine.vi.cs index f6c0441..d7023f8 100644 --- a/PSReadLine/ReadLine.vi.cs +++ b/PSReadLine/ReadLine.vi.cs @@ -985,8 +985,7 @@ namespace Microsoft.PowerShell return; } - Dictionary secondKeyDispatchTable; - if (_singleton._chordDispatchTable.TryGetValue(key.Value, out secondKeyDispatchTable)) + if (_singleton._chordDispatchTable.TryGetValue(key.Value, out var secondKeyDispatchTable)) { //if (_singleton._demoMode) //{ @@ -994,8 +993,7 @@ namespace Microsoft.PowerShell // _singleton.Render(); //} var secondKey = ReadKey(); - KeyHandler handler; - if (secondKeyDispatchTable.TryGetValue(secondKey, out handler)) + if (secondKeyDispatchTable.TryGetValue(secondKey, out var handler)) { _singleton.ProcessOneKey(secondKey, secondKeyDispatchTable, ignoreIfNoAction: true, arg: arg); } @@ -1070,8 +1068,7 @@ namespace Microsoft.PowerShell while (true) { var nextKey = ReadKey(); - KeyHandler handler; - if (_singleton._dispatchTable.TryGetValue(nextKey, out handler) && handler.Action == DigitArgument) + if (_singleton._dispatchTable.TryGetValue(nextKey, out var handler) && handler.Action == DigitArgument) { if (nextKey.KeyChar == '-') { @@ -1102,8 +1099,7 @@ namespace Microsoft.PowerShell } } - int intArg; - if (int.TryParse(argBuffer.ToString(), out intArg)) + if (int.TryParse(argBuffer.ToString(), out var intArg)) { _singleton.ProcessOneKey(nextKey, _singleton._dispatchTable, ignoreIfNoAction: false, arg: intArg); } diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 2288f15..05b6796 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -680,8 +680,7 @@ namespace Microsoft.PowerShell /// public static void ScrollDisplayUp(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, +1); + TryGetArgAsInt(arg, out var numericArg, +1); var console = _singleton._console; var newTop = console.WindowTop - (numericArg * console.WindowHeight); if (newTop < 0) @@ -696,8 +695,7 @@ namespace Microsoft.PowerShell /// public static void ScrollDisplayUpLine(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, +1); + TryGetArgAsInt(arg, out var numericArg, +1); var console = _singleton._console; var newTop = console.WindowTop - numericArg; if (newTop < 0) @@ -712,8 +710,7 @@ namespace Microsoft.PowerShell /// public static void ScrollDisplayDown(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, +1); + TryGetArgAsInt(arg, out var numericArg, +1); var console = _singleton._console; var newTop = console.WindowTop + (numericArg * console.WindowHeight); if (newTop > (console.BufferHeight - console.WindowHeight)) @@ -728,8 +725,7 @@ namespace Microsoft.PowerShell /// public static void ScrollDisplayDownLine(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - TryGetArgAsInt(arg, out numericArg, +1); + TryGetArgAsInt(arg, out var numericArg, +1); var console = _singleton._console; var newTop = console.WindowTop + numericArg; if (newTop > (console.BufferHeight - console.WindowHeight)) diff --git a/PSReadLine/YankPaste.vi.cs b/PSReadLine/YankPaste.vi.cs index 93e383c..0d3a86c 100644 --- a/PSReadLine/YankPaste.vi.cs +++ b/PSReadLine/YankPaste.vi.cs @@ -73,8 +73,7 @@ namespace Microsoft.PowerShell /// public static void ViYankRight(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -95,8 +94,7 @@ namespace Microsoft.PowerShell /// public static void ViYankLeft(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -137,8 +135,7 @@ namespace Microsoft.PowerShell /// public static void ViYankPreviousWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -162,8 +159,7 @@ namespace Microsoft.PowerShell /// public static void ViYankNextWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -191,8 +187,7 @@ namespace Microsoft.PowerShell /// public static void ViYankEndOfWord(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -216,8 +211,7 @@ namespace Microsoft.PowerShell /// public static void ViYankEndOfGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -295,8 +289,7 @@ namespace Microsoft.PowerShell /// public static void ViYankPreviousGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; } @@ -321,8 +314,7 @@ namespace Microsoft.PowerShell /// public static void ViYankNextGlob(ConsoleKeyInfo? key = null, object arg = null) { - int numericArg; - if (!TryGetArgAsInt(arg, out numericArg, 1)) + if (!TryGetArgAsInt(arg, out var numericArg, 1)) { return; }