/// <summary>
        /// Creates (but does not throw) an exception for this result. The result must not be successful.
        /// </summary>
        public static Exception CreateExceptionForError(this EnumerateDirectoryResult result)
        {
            Contract.Requires(result.Status != EnumerateDirectoryStatus.Success);
            var errorMessage = I($"Enumerating a directory failed: {result.Status:G}");

            return(result.ErrorCause != null
                ? new Exception(errorMessage, result.ErrorCause)
                : new NativeWin32Exception(result.NativeErrorCode));
        }
 /// <summary>
 /// Throws an exception if the native error code was corresponds to a known <see cref="EnumerateDirectoryStatus"/>
 /// (and enumeration was not successful).
 /// </summary>
 public static Exception ThrowForKnownError(this EnumerateDirectoryResult result)
 {
     Contract.Requires(result.Status != EnumerateDirectoryStatus.UnknownError && result.Status != EnumerateDirectoryStatus.Success);
     throw result.CreateExceptionForError();
 }