Closed MattKotsenas closed 1 year ago
I'm happy to open a PR here if this feature request is approved, but I wanted to check first before spending time on it. If you have any questions or concerns, please let me know. Thanks!
Hi @MattKotsenas. I like the idea but I would change the naming. I would call it "DisposableDirectory" instead of "TemporaryDirectory" as I feel it could be confusing as "temporary" is already used. Also, I would return the IDirectoryInfo as an out parameter of the CreateDisposableDirectory in order to reduce typing. That would also make the new interface redundant. Hope the above notes makes sense. Let me know what you think. I would be happy to merge a PR on this but please make sure there is coverage.
@gigi81 Thanks! I'm open to anything that improves developer experience. I'll get started on this and post a PR; also happy to iterate on naming and API shape there as well.
This is addressed in release v1.0.43.
Is your feature request related to a problem? Please describe.
Console apps often need to create temp files / folders to do work in, but then want to ensure that the temp files are cleaned up before the program exits. Today this is usually accomplished with code like this:
while this code works fine, it's a bit clunky (in my opinion) as the temp item needs to be manually created and destroyed, and the code can possibly be separated by many lines, making it more difficult to recognize it as the "temp file pattern".
Describe the solution you'd like
Ideally a
TempFile
/TempDirectory
class that implementsIDisposable
so that ausing
statement can create and destroy my temp file for me when it goes out-of-scope. This is often referred to as the RAII pattern.The interface for a directory could be as simple as this:
with a sample usage like this:
Describe alternatives you've considered
I've implemented this pattern in projects in the past, the intent here is to create a generic and reusable one.
Additional context
None