public override async Task DeleteAsync(DeletionOption options, CancellationToken cancellationToken = default) { if (!EnumInfo.IsDefined(options)) { throw new ArgumentException(ExceptionStrings.Enum.UndefinedValue(options), nameof(options)); } cancellationToken.ThrowIfCancellationRequested(); lock (_inMemoryFileSystem.Storage) { switch (options) { case DeletionOption.Fail: _storage.GetFolderNode(Path).Delete(); break; case DeletionOption.IgnoreMissing: _storage.TryGetFolderNodeAndThrowOnConflictingFile(Path)?.Delete(); break; default: throw new NotSupportedException(ExceptionStrings.Enum.UnsupportedValue(options)); } } }
public override Task DeleteAsync(DeletionOption options, CancellationToken cancellationToken = default) { if (!EnumInfo.IsDefined(options)) { throw new ArgumentException(ExceptionStrings.Enum.UndefinedValue(options), nameof(options)); } return(options switch { DeletionOption.Fail => FailImpl(), DeletionOption.IgnoreMissing => IgnoreMissingImpl(), _ => throw new NotSupportedException(ExceptionStrings.Enum.UnsupportedValue(options)), });
/// <summary> /// Deletes the element (and all of its children if it is a <see cref="StorageFolder"/>). /// </summary> /// <param name="options"> /// Defines how to react when the element to be deleted does not exist. /// </param> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="options"/> is an invalid <see cref="DeletionOption"/> value. /// </exception> /// <exception cref="OperationCanceledException"> /// The operation was cancelled via the specified <paramref name="cancellationToken"/>. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// Access to the element is restricted. /// </exception> /// <exception cref="PathTooLongException"> /// The length of the element's path exceeds the system-defined maximum length. /// </exception> /// <exception cref="IOException"> /// The element is a <see cref="StorageFile"/> (or <see cref="StorageFolder"/>) and a /// conflicting folder (or file) exists at its path. /// /// -or- /// /// An undefined I/O error occured while interacting with the file system. /// </exception> /// <exception cref="FileNotFoundException"> /// The element is a <see cref="StorageFile"/> which does not exist and <paramref name="options"/> /// has the value <see cref="DeletionOption.Fail"/>. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// One of the element's parent folders does not exist. /// /// -or- /// /// The element is a <see cref="StorageFolder"/> which does not exist and <paramref name="options"/> /// has the value <see cref="DeletionOption.Fail"/>. /// </exception> public abstract Task DeleteAsync(DeletionOption options, CancellationToken cancellationToken = default);