mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 10:08:57 +00:00
45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Microsoft.AspNetCore.NodeServices
|
|
{
|
|
// Makes it easier to pass script files to Node in a way that's sure to clean up after the process exits
|
|
public sealed class StringAsTempFile : IDisposable
|
|
{
|
|
private bool _disposedValue;
|
|
|
|
public StringAsTempFile(string content)
|
|
{
|
|
FileName = Path.GetTempFileName();
|
|
File.WriteAllText(FileName, content);
|
|
}
|
|
|
|
public string FileName { get; }
|
|
|
|
public void Dispose()
|
|
{
|
|
DisposeImpl(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
private void DisposeImpl(bool disposing)
|
|
{
|
|
if (!_disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// Would dispose managed state here, if there was any
|
|
}
|
|
|
|
File.Delete(FileName);
|
|
|
|
_disposedValue = true;
|
|
}
|
|
}
|
|
|
|
~StringAsTempFile()
|
|
{
|
|
DisposeImpl(false);
|
|
}
|
|
}
|
|
} |