From 1fc5bed9fb4cc1e262dfe40e00bbd27dd674c686 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 23 Nov 2020 02:47:38 +0000 Subject: [PATCH] Fix CA1822: Mark members as static part 5 https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822 --- .../host/msh/ConsoleHost.cs | 12 ++++++++---- .../host/msh/ConsoleHostRawUserInterface.cs | 2 +- .../host/msh/ConsoleHostUserInterface.cs | 6 +++--- .../host/msh/Executor.cs | 2 +- .../host/msh/PendingProgress.cs | 4 ++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 98e5ff2b1b4..8d8d3a557e1 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -224,7 +224,7 @@ internal static int Start(string bannerText, string helpText) throw hostException; } - if (s_theConsoleHost.LoadPSReadline()) + if (LoadPSReadline()) { ProfileOptimization.StartProfile("StartupProfileData-Interactive"); @@ -1156,6 +1156,10 @@ internal ConsoleHost() AppDomain.CurrentDomain.UnhandledException += handler; } + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Performance", + "CA1822:Mark members as static", + Justification = "Accesses instance members in preprocessor branch.")] private void BindBreakHandler() { #if UNIX @@ -1598,7 +1602,7 @@ private bool IsScreenReaderActive() return _screenReaderActive.Value; } - private bool LoadPSReadline() + private static bool LoadPSReadline() { // Don't load PSReadline if: // * we don't think the process will be interactive, e.g. -command or -file @@ -1706,7 +1710,7 @@ private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool sta DoRunspaceInitialization(skipProfiles, initialCommand, configurationName, initialCommandArgs); } - private void OpenConsoleRunspace(Runspace runspace, bool staMode) + private static void OpenConsoleRunspace(Runspace runspace, bool staMode) { if (staMode && Platform.IsWindowsDesktop) { @@ -2726,7 +2730,7 @@ private DebuggerCommandResults ProcessDebugCommand(string cmd, out Exception e) return results ?? new DebuggerCommandResults(DebuggerResumeAction.Continue, false); } - private bool IsIncompleteParseException(Exception e) + private static bool IsIncompleteParseException(Exception e) { // Check e's type. if (e is IncompleteParseException) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index c4946b5431e..a189481ce98 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -548,7 +548,7 @@ public override /// Helper method to create and trace PipelineStoppedException. /// /// - private PipelineStoppedException NewPipelineStoppedException() + private static PipelineStoppedException NewPipelineStoppedException() { PipelineStoppedException e = new PipelineStoppedException(); return e; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index bbe0a82bb15..c67db4cb525 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -619,7 +619,7 @@ private void WriteToConsole(ConsoleColor foregroundColor, ConsoleColor backgroun } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ConsoleOutWriteHelper(ReadOnlySpan value, bool newLine) + private static void ConsoleOutWriteHelper(ReadOnlySpan value, bool newLine) { if (newLine) { @@ -1847,7 +1847,7 @@ private char GetCharacterUnderCursor(Coordinates cursorPosition) /// /// The string to process. /// The string with any \0 characters removed... - private string RemoveNulls(string input) + private static string RemoveNulls(string input) { if (input.Contains('\0')) { @@ -2042,7 +2042,7 @@ internal string ReadLineWithTabCompletion(Executor exec) } #if !UNIX - private void SendLeftArrows(int length) + private static void SendLeftArrows(int length) { var inputs = new ConsoleControl.INPUT[length * 2]; for (int i = 0; i < length; i++) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs index 266d078ee68..68df51be539 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs @@ -342,7 +342,7 @@ internal Collection ExecuteCommand(string command, out Exception excep return ExecuteCommandHelper(tempPipeline, out exceptionThrown, options); } - private Command GetOutDefaultCommand(bool endOfStatement) + private static Command GetOutDefaultCommand(bool endOfStatement) { return new Command(command: "Out-Default", isScript: false, diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs index 31fdb49b35b..1588efe6b0e 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs @@ -298,6 +298,10 @@ internal override private int _oldestSoFar; } + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Performance", + "CA1822:Mark members as static", + Justification = "Accesses instance members in preprocessor branch.")] private ProgressNode FindOldestLeafmostNodeHelper(ArrayList treeToSearch, out ArrayList listWhereFound, out int indexWhereFound)