public IAsyncOperationWithProgress <IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
{
if (buffer == null)
{
// Mapped to E_POINTER.
throw new ArgumentNullException(nameof(buffer));
}
if (count < 0 || int.MaxValue < count)
{
ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(nameof(count));
ex.HResult = __HResults.E_INVALIDARG;
throw ex;
}
if (buffer.Capacity < count)
{
ArgumentException ex = new ArgumentException(SR.Argument_InsufficientBufferCapacity);
ex.HResult = __HResults.E_INVALIDARG;
throw ex;
}
if (!(options == InputStreamOptions.None || options == InputStreamOptions.Partial || options == InputStreamOptions.ReadAhead))
{
ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(nameof(options),
SR.ArgumentOutOfRange_InvalidInputStreamOptionsEnumValue);
ex.HResult = __HResults.E_INVALIDARG;
throw ex;
}
Stream str = EnsureNotDisposed();
IAsyncOperationWithProgress <IBuffer, uint> readAsyncOperation;
switch (_readOptimization)
{
case StreamReadOperationOptimization.MemoryStream:
readAsyncOperation = StreamOperationsImplementation.ReadAsync_MemoryStream(str, buffer, count);
break;
case StreamReadOperationOptimization.AbstractStream:
readAsyncOperation = StreamOperationsImplementation.ReadAsync_AbstractStream(str, buffer, count, options);
break;
// Use this pattern to add more optimisation options if necessary:
//case StreamReadOperationOptimization.XxxxStream:
// readAsyncOperation = StreamOperationsImplementation.ReadAsync_XxxxStream(str, buffer, count, options);
// break;
default:
Debug.Fail("We should never get here. Someone forgot to handle an input stream optimisation option.");
readAsyncOperation = null;
break;
}
return(readAsyncOperation);
}