Implement IDisposable for ConvertToJsonCommand (#15787)

This commit is contained in:
xtqqczze
2021-07-20 13:26:28 -07:00
committed by GitHub
parent 06f7e1050a
commit 9ceed485af
@@ -16,7 +16,7 @@ namespace Microsoft.PowerShell.Commands
/// This command converts an object to a Json string representation.
/// </summary>
[Cmdlet(VerbsData.ConvertTo, "Json", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2096925", RemotingCapability = RemotingCapability.None)]
public class ConvertToJsonCommand : PSCmdlet
public class ConvertToJsonCommand : PSCmdlet, IDisposable
{
/// <summary>
/// Gets or sets the InputObject property.
@@ -77,6 +77,29 @@ namespace Microsoft.PowerShell.Commands
[Parameter]
public StringEscapeHandling EscapeHandling { get; set; } = StringEscapeHandling.Default;
/// <summary>
/// IDisposable implementation, dispose of any disposable resources created by the cmdlet.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Implementation of IDisposable for both manual Dispose() and finalizer-called disposal of resources.
/// </summary>
/// <param name="disposing">
/// Specified as true when Dispose() was called, false if this is called from the finalizer.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_cancellationSource.Dispose();
}
}
/// <summary>
/// Prerequisite checks.
/// </summary>