mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0090
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
using System.IO;
|
|
using System.Management.Automation;
|
|
|
|
namespace Microsoft.PowerShell.Commands
|
|
{
|
|
/// <summary>
|
|
/// The implementation of the "New-TemporaryFile" cmdlet.
|
|
/// </summary>
|
|
[Cmdlet(VerbsCommon.New, "TemporaryFile", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Low,
|
|
HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2097032")]
|
|
[OutputType(typeof(System.IO.FileInfo))]
|
|
public class NewTemporaryFileCommand : Cmdlet
|
|
{
|
|
/// <summary>
|
|
/// Returns a TemporaryFile.
|
|
/// </summary>
|
|
protected override void EndProcessing()
|
|
{
|
|
string filePath = null;
|
|
string tempPath = Path.GetTempPath();
|
|
if (ShouldProcess(tempPath))
|
|
{
|
|
try
|
|
{
|
|
filePath = Path.GetTempFileName();
|
|
}
|
|
catch (IOException ioException)
|
|
{
|
|
ThrowTerminatingError(
|
|
new ErrorRecord(
|
|
ioException,
|
|
"NewTemporaryFileWriteError",
|
|
ErrorCategory.WriteError,
|
|
tempPath));
|
|
return;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
{
|
|
FileInfo file = new(filePath);
|
|
WriteObject(file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|