From 3127d09ec44fbfef6665f1e14631008c4577a951 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 19 Jul 2021 15:03:44 +0100 Subject: [PATCH 1/4] Seal `ClientRemotePowerShell` Seal `System.Management.Automation.Runspaces.Internal.ClientRemotePowerShell` --- .../engine/remoting/client/ClientRemotePowerShell.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs index 4ea06ea2feb..7a0a9e99107 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs @@ -15,7 +15,7 @@ namespace System.Management.Automation.Runspaces.Internal /// PowerShell client side proxy base which handles invocation /// of powershell on a remote machine. /// - internal class ClientRemotePowerShell : IDisposable + internal sealed class ClientRemotePowerShell : IDisposable { #region Tracer From e39499204f4a2e9607103ac30134890b94892def Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 19 Jul 2021 15:06:26 +0100 Subject: [PATCH 2/4] Fix CS0628 Fix [CS0628: new protected member declared in sealed class](https://docs.microsoft.com/dotnet/csharp/misc/cs0628) --- .../remoting/client/ClientRemotePowerShell.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs index 7a0a9e99107..3ee8a9f8688 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs @@ -902,28 +902,28 @@ private void HandleRobustConnectionNotification( #endregion Private Methods - #region Protected Members - - protected ObjectStreamBase inputstream; - protected ObjectStreamBase errorstream; - protected PSInformationalBuffers informationalBuffers; - protected PowerShell shell; - protected Guid clientRunspacePoolId; - protected bool noInput; - protected PSInvocationSettings settings; - protected ObjectStreamBase outputstream; - protected string computerName; - protected ClientPowerShellDataStructureHandler dataStructureHandler; - protected bool stopCalled = false; - protected PSHost hostToUse; - protected RemoteRunspacePoolInternal runspacePool; - - protected const string WRITE_DEBUG_LINE = "WriteDebugLine"; - protected const string WRITE_VERBOSE_LINE = "WriteVerboseLine"; - protected const string WRITE_WARNING_LINE = "WriteWarningLine"; - protected const string WRITE_PROGRESS = "WriteProgress"; - - protected bool initialized = false; + #region Private Fields + + private ObjectStreamBase inputstream; + private ObjectStreamBase errorstream; + private PSInformationalBuffers informationalBuffers; + private PowerShell shell; + private Guid clientRunspacePoolId; + private bool noInput; + private PSInvocationSettings settings; + private ObjectStreamBase outputstream; + private string computerName; + private ClientPowerShellDataStructureHandler dataStructureHandler; + private bool stopCalled = false; + private PSHost hostToUse; + private RemoteRunspacePoolInternal runspacePool; + + private const string WRITE_DEBUG_LINE = "WriteDebugLine"; + private const string WRITE_VERBOSE_LINE = "WriteVerboseLine"; + private const string WRITE_WARNING_LINE = "WriteWarningLine"; + private const string WRITE_PROGRESS = "WriteProgress"; + + private bool initialized = false; /// /// This queue is for the state change events that resulted in closing the underlying /// datastructure handler. We cannot send the state back to the upper layers until @@ -933,7 +933,7 @@ private void HandleRobustConnectionNotification( private PSConnectionRetryStatus _connectionRetryStatus = PSConnectionRetryStatus.None; - #endregion Protected Members + #endregion Private Fields #region IDisposable @@ -951,7 +951,7 @@ public void Dispose() /// Release all resources. /// /// If true, release all managed resources. - protected void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing) { From 3bcd1c875026b785c6993c181848d86c57bfb0f2 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 19 Jul 2021 15:07:48 +0100 Subject: [PATCH 3/4] Fix IDE0044 Fix [IDE0044: Add readonly modifier](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0044) --- .../engine/remoting/client/ClientRemotePowerShell.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs index 3ee8a9f8688..d8b16e43cc6 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs @@ -907,16 +907,16 @@ private void HandleRobustConnectionNotification( private ObjectStreamBase inputstream; private ObjectStreamBase errorstream; private PSInformationalBuffers informationalBuffers; - private PowerShell shell; - private Guid clientRunspacePoolId; + private readonly PowerShell shell; + private readonly Guid clientRunspacePoolId; private bool noInput; private PSInvocationSettings settings; private ObjectStreamBase outputstream; - private string computerName; + private readonly string computerName; private ClientPowerShellDataStructureHandler dataStructureHandler; private bool stopCalled = false; private PSHost hostToUse; - private RemoteRunspacePoolInternal runspacePool; + private readonly RemoteRunspacePoolInternal runspacePool; private const string WRITE_DEBUG_LINE = "WriteDebugLine"; private const string WRITE_VERBOSE_LINE = "WriteVerboseLine"; From b09d6aae04b7d345857cc3b6bc13b606706dcb6a Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 19 Jul 2021 15:21:06 +0100 Subject: [PATCH 4/4] Simplify IDisposable implementation --- .../remoting/client/ClientRemotePowerShell.cs | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs index d8b16e43cc6..b464028d851 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientRemotePowerShell.cs @@ -938,28 +938,15 @@ private void HandleRobustConnectionNotification( #region IDisposable /// - /// Public interface for dispose. + /// Release all resources. /// public void Dispose() { - Dispose(true); - - GC.SuppressFinalize(this); + // inputstream.Dispose(); + // outputstream.Dispose(); + // errorstream.Dispose(); } - /// - /// Release all resources. - /// - /// If true, release all managed resources. - private void Dispose(bool disposing) - { - if (disposing) - { - // inputstream.Dispose(); - // outputstream.Dispose(); - // errorstream.Dispose(); - } - } #endregion IDisposable }