Enable CA1816: Dispose methods should call SuppressFinalize (#14074)
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1816
This commit is contained in:
parent
cb6ef9bdee
commit
358db74479
|
@ -268,7 +268,7 @@ dotnet_diagnostic.CA1814.severity = none
|
|||
dotnet_diagnostic.CA1815.severity = none
|
||||
|
||||
# CA1816: Dispose methods should call SuppressFinalize
|
||||
dotnet_diagnostic.CA1816.severity = suggestion
|
||||
dotnet_diagnostic.CA1816.severity = warning
|
||||
|
||||
# CA1819: Properties should not return arrays
|
||||
dotnet_diagnostic.CA1819.severity = none
|
||||
|
|
|
@ -101,11 +101,28 @@ namespace Microsoft.PowerShell.Commands
|
|||
#region "IDisposable Members"
|
||||
|
||||
/// <summary>
|
||||
/// Dispose Method.
|
||||
/// Releases all resources used by the <see cref="CommandLineCmdletBase"/>.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_process?.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the <see cref="CommandLineCmdletBase"/>
|
||||
/// and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true"/> to release both managed and unmanaged resources;
|
||||
/// <see langword="false"/> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_process?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion "IDisposable Members"
|
||||
|
|
|
@ -39,9 +39,18 @@ namespace PSTests.Parallel
|
|||
File.AppendAllText(testPath, testContent);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
public void Dispose()
|
||||
{
|
||||
File.Delete(testPath);
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
File.Delete(testPath);
|
||||
}
|
||||
}
|
||||
|
||||
private ExecutionContext GetExecutionContext()
|
||||
|
|
|
@ -97,18 +97,27 @@ namespace PSTests.Sequential
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
CleanupConfigFiles();
|
||||
if (systemWideConfigBackupFile != null)
|
||||
{
|
||||
File.Move(systemWideConfigBackupFile, systemWideConfigFile);
|
||||
}
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
if (currentUserConfigBackupFile != null)
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
|
||||
}
|
||||
CleanupConfigFiles();
|
||||
if (systemWideConfigBackupFile != null)
|
||||
{
|
||||
File.Move(systemWideConfigBackupFile, systemWideConfigFile);
|
||||
}
|
||||
|
||||
InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
|
||||
if (currentUserConfigBackupFile != null)
|
||||
{
|
||||
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
|
||||
}
|
||||
|
||||
InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
|
||||
}
|
||||
}
|
||||
|
||||
internal PowerShellPolicies SystemWidePolicies
|
||||
|
|
Loading…
Reference in a new issue