From 8316bedb287382125e82daefb6e28f9d23b69e85 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 17 Mar 2021 13:28:08 +0000 Subject: [PATCH 1/4] Remove unnecessary Array -> List -> Array conversion Change removes redundant code from ProcessBaseCommand.AllProcesse that was left after existing functionality was removed in #4960. --- .../commands/management/Process.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 6656dcc549b..5e0fd23b6b4 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -278,14 +278,7 @@ internal Process[] AllProcesses { get { - if (_allProcesses == null) - { - List processes = new(); - processes.AddRange(Process.GetProcesses()); - _allProcesses = processes.ToArray(); - } - - return _allProcesses; + return _allProcesses ??= Process.GetProcesses(); } } From f8f8550c84606a2ef77ea1d54cb3bb0932c68d0e Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 17 Mar 2021 13:28:47 +0000 Subject: [PATCH 2/4] Fix IDE0025: Use expression body --- .../commands/management/Process.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 5e0fd23b6b4..fbd1d03b3a0 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -274,13 +274,7 @@ private void RetrieveProcessesByInput() /// but it is reasonable to expect that SecurityException is /// among them. Errors here will terminate the cmdlet. /// - internal Process[] AllProcesses - { - get - { - return _allProcesses ??= Process.GetProcesses(); - } - } + internal Process[] AllProcesses => _allProcesses ??= Process.GetProcesses(); private Process[] _allProcesses = null; From 2552ca336bae9c73bb7071d3532a1705bb6ed1a2 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 17 Mar 2021 13:29:17 +0000 Subject: [PATCH 3/4] Remove redundant initialization --- .../commands/management/Process.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index fbd1d03b3a0..74ac3bb9461 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -276,7 +276,7 @@ private void RetrieveProcessesByInput() /// internal Process[] AllProcesses => _allProcesses ??= Process.GetProcesses(); - private Process[] _allProcesses = null; + private Process[] _allProcesses; /// /// Add to , From 1e2a12f95d94f15c248c9a369eebe8da37054f64 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 17 Mar 2021 13:59:48 +0000 Subject: [PATCH 4/4] Update documentation comments --- .../commands/management/Process.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 74ac3bb9461..1680e17bee1 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -266,9 +266,9 @@ private void RetrieveProcessesByInput() } /// - /// Retrieve the master list of all processes. + /// Gets an array of all processes. /// - /// + /// An array of components that represents all the process resources. /// /// MSDN does not document the list of exceptions, /// but it is reasonable to expect that SecurityException is