From 8611c8667320e01393fd6447efc6f58ceca56492 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Tue, 24 Nov 2020 07:26:04 +0000
Subject: [PATCH] Fix CA1822: Mark members as static part 5 (#14228)
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 568f290d43..55b3a04c3e 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
@@ -224,7 +224,7 @@ namespace Microsoft.PowerShell
throw hostException;
}
- if (s_theConsoleHost.LoadPSReadline())
+ if (LoadPSReadline())
{
ProfileOptimization.StartProfile("StartupProfileData-Interactive");
@@ -1156,6 +1156,10 @@ namespace Microsoft.PowerShell
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 @@ namespace Microsoft.PowerShell
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 @@ namespace Microsoft.PowerShell
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 @@ namespace Microsoft.PowerShell
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 c4946b5431..a189481ce9 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
@@ -548,7 +548,7 @@ namespace Microsoft.PowerShell
/// 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 fa05f2424a..5c319347a8 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs
@@ -619,7 +619,7 @@ namespace Microsoft.PowerShell
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private void ConsoleOutWriteHelper(ReadOnlySpan value, bool newLine)
+ private static void ConsoleOutWriteHelper(ReadOnlySpan value, bool newLine)
{
if (newLine)
{
@@ -1847,7 +1847,7 @@ namespace Microsoft.PowerShell
///
/// 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 @@ namespace Microsoft.PowerShell
}
#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 266d078ee6..68df51be53 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
@@ -342,7 +342,7 @@ namespace Microsoft.PowerShell
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 31fdb49b35..1588efe6b0 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs
@@ -298,6 +298,10 @@ namespace Microsoft.PowerShell
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)