Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure TemproryFile is as good as tmpfile from C/C++ or better. #82

Open
Konard opened this issue Mar 3, 2022 · 0 comments
Open

Comments

@Konard
Copy link
Member

Konard commented Mar 3, 2022

/// <summary>
/// <para>Represents a self-deleting temporary file.</para>
/// <para>Представляет самоудаляющийся временный файл.</para>
/// </summary>
public class TemporaryFile : DisposableBase
{
/// <summary>
/// <para>Gets a temporary file path.</para>
/// <para>Возвращает путь к временному файлу.</para>
/// </summary>
public readonly string Filename;
/// <summary>
/// <para>Converts the <see cref="TemporaryFile"/> instance to <see cref="string"/> using the <see cref="Filename"/> field value.</para>
/// <para>Преобразует экземпляр <see cref="TemporaryFile"/> в <see cref="string"/> используя поле <see cref="Filename"/>.</para>
/// </summary>
/// <param name="file">
/// <para>A <see cref="TemporaryFile"/> instance.</para>
/// <para>Экземпляр <see cref="TemporaryFile"/>.</para>
/// </param>
/// <returns>
/// <para>Path to the temporary file.</para>
/// <para>Путь к временному файлу.</para>
/// </returns>
public static implicit operator string(TemporaryFile file) => file.Filename;
/// <summary>
/// <para>Initializes a <see cref="TemporaryFile"/> instance.</para>
/// <para>Инициализирует экземпляр класса <see cref="TemporaryFile"/>.</para>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TemporaryFile() => Filename = TemporaryFiles.UseNew();
/// <summary>
/// <para>Deletes the temporary file.</para>
/// <para>Удаляет временный файл.</para>
/// </summary>
/// <param name="manual">
/// <para>A <see cref="Boolean"/> value that determines whether the disposal was triggered manually (by the developer's code) or was executed automatically without an explicit indication from a developer.</para>
/// <para>Значение типа <see cref="Boolean"/>, определяющие было ли высвобождение вызвано вручную (кодом разработчика) или же выполнилось автоматически без явного указания со стороны разработчика.</para>
/// </param>
/// <param name="wasDisposed">
/// <para>A <see cref="Boolean"/> value that determines whether the <see cref="TemporaryFile"/> was released before a call to this method.</para>
/// <para>Значение типа <see cref="Boolean"/>, определяющие были ли освобождены ресурсы, используемые <see cref="TemporaryFile"/> до вызова данного метода.</para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void Dispose(bool manual, bool wasDisposed)
{
if (!wasDisposed)
{
File.Delete(Filename);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant