-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
API Proposal
namespace System.IO
{
public static class FileHandleExtensions
{
public static DateTime GetLastWriteTimeUtc(this SafeFileHandle fileHandle);
public static void SetLastWriteTimeUtc(this SafeFileHandle fileHandle, DateTime time);
public static DateTime GetLastAccessTimeUtc(this SafeFileHandle fileHandle);
public static void SetLastAccessTimeUtc(this SafeFileHandle fileHandle, DateTime time);
public static DateTime GetCreationTimeUtc(this SafeFileHandle fileHandle);
public static void SetCreationTimeUtc(this SafeFileHandle fileHandle, DateTime time);
}
}Original post
I know that in many cases it is ok to do so, but we found ourself in the case where we need to set file times without closing the actual FileStream, and this is possible via Windows API.
To do so we had to write unsafe code which mimic the functionality of the existing functions.
(which include rewriting System.IO.__Error.WinIOError(), this is obviusly a bad thing, because we have to maintain code wich already exist)
This could be extremely more usable and maintainable if the framework exposed those methods as SafeFileHandle Method/ExtensionMethod.
My proposal is to leave those functions unaltered but move the actual implementation in an ipotetic function:
SafeFileHandle.SetFileTimesUtc(DateTime? creationTimeUtc, DateTime? lastAccessTimeUtc, DateTime? lastWriteTimeUtc) which should be public.