private void CheckCurrent(ClipboardDataFormat need) { if (CurrentRetenteFormat != need) { throw new InvalidOperationException($"Current data format is {need}"); } }
/// <summary> /// Gets right <seealso cref="IClipboardDataChecker" /> instance for the given format. /// </summary> /// <exception cref="ArgumentOutOfRangeException"><paramref name="format" /> is unknown.</exception> private IClipboardDataChecker GetDataChecker(ClipboardDataFormat format) { return(format switch { ClipboardDataFormat.Text => _clipboardModifierFactory.Get <StringReader>(), ClipboardDataFormat.FileDropList => _clipboardModifierFactory.Get <StringReader>(), _ => throw new ArgumentOutOfRangeException(nameof(format), format, $"{nameof(format)} is unknown.") });
/// <summary> /// Gets right <seealso cref="IClipboardDataChecker" /> instance for the given format. /// </summary> /// <exception cref="ArgumentOutOfRangeException"><see cref="format" /> is unknown.</exception> private IClipboardDataChecker GetDataChecker(ClipboardDataFormat format) { switch (format) { case ClipboardDataFormat.Text: return(_clipboardModifierFactory.Get <StringReader>()); case ClipboardDataFormat.FileDropList: return(_clipboardModifierFactory.Get <StringReader>()); default: throw new ArgumentOutOfRangeException(nameof(format), format, $"{nameof(format)} is unknown."); } }
/// <inheritdoc /> /// <remarks> /// The alternative way of checking if the data format exists can be using one of Get methods and check if the result /// is <see langword="null" />. /// Because get methods (<see cref="GetTextAsync" />, <see cref="GetFileDropListAsync" />, /// <see cref="GetAsUnicodeBytesAsync" />) /// returns <see langword="null" />, if the clipboard does not contain any data that is in the wanted format or /// can be converted to that format. /// <example> /// <code> /// var result = await ContainsAsync(ClipboardDataFormat.Text); //returns if text format exists in the clipboard /// var same = await GetTextAsync() == null; //gives same result /// </code> /// </example> /// </remarks> /// <exception cref="ArgumentOutOfRangeException"><paramref name="format" /> is unknown.</exception> /// <seealso cref="ClipboardDataFormat" /> public Task <bool> ContainsAsync(ClipboardDataFormat format) { var checker = GetDataChecker(format); return(checker.ExistsAsync()); }