Enable CA1837: Use 'Environment.ProcessId' (#14063)

https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1837
This commit is contained in:
xtqqczze 2020-11-13 03:47:23 +00:00 committed by GitHub
parent 8148968546
commit 5c874207ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 8 additions and 8 deletions

View file

@ -323,7 +323,7 @@ dotnet_diagnostic.CA1835.severity = suggestion
dotnet_diagnostic.CA1836.severity = warning
# CA1837: Use 'Environment.ProcessId'
dotnet_diagnostic.CA1837.severity = suggestion
dotnet_diagnostic.CA1837.severity = warning
# CA1838: Avoid 'StringBuilder' parameters for P/Invokes
dotnet_diagnostic.CA1838.severity = silent

View file

@ -974,7 +974,7 @@ namespace Microsoft.PowerShell.Commands
}
// It cannot wait on itself
if (process.Id.Equals(System.Diagnostics.Process.GetCurrentProcess().Id))
if (process.Id.Equals(Environment.ProcessId))
{
WriteNonTerminatingError(process, null, ProcessResources.WaitOnItself, "WaitOnItself", ErrorCategory.ObjectNotFound);
continue;
@ -1214,7 +1214,7 @@ namespace Microsoft.PowerShell.Commands
try
{
if (Process.GetCurrentProcess().Id == SafeGetProcessId(process))
if (Environment.ProcessId == SafeGetProcessId(process))
{
_shouldKillCurrentProcess = true;
continue;

View file

@ -137,7 +137,7 @@ namespace System.Management.Automation
{
if (!this._processId.HasValue)
{
this._processId = (uint)System.Diagnostics.Process.GetCurrentProcess().Id;
this._processId = (uint)Environment.ProcessId;
}
return this._processId.Value;

View file

@ -511,7 +511,7 @@ namespace System.Management.Automation.Host
Environment.MachineName,
Environment.OSVersion.VersionString,
string.Join(" ", Environment.GetCommandLineArgs()),
System.Diagnostics.Process.GetCurrentProcess().Id,
Environment.ProcessId,
versionInfoFooter.ToString().TrimEnd());
}

View file

@ -377,7 +377,7 @@ namespace Microsoft.PowerShell.Commands
private void VerifyProcess(Process process)
{
if (process.Id == Process.GetCurrentProcess().Id)
if (process.Id == Environment.ProcessId)
{
ThrowTerminatingError(
new ErrorRecord(

View file

@ -744,7 +744,7 @@ namespace System.Management.Automation.Remoting
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Runtime.InteropServices.SafeHandle.DangerousGetHandle")]
private void ProcessListeningThread(object state)
{
string processId = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);
string processId = Environment.ProcessId.ToString(CultureInfo.InvariantCulture);
string appDomainName = NamedPipeUtils.GetCurrentAppDomainName();
// Logging.

View file

@ -78,7 +78,7 @@ namespace System.Management.Automation
// Cache of the current process' parentId
private static int? s_currentParentProcessId;
private static readonly int s_currentProcessId = Process.GetCurrentProcess().Id;
private static readonly int s_currentProcessId = Environment.ProcessId;
/// <summary>
/// Retrieve the parent process of a process.