/// <summary>
        /// Writes data to a byte stream.
        /// </summary>
        /// <typeparam name="T">A value type.</typeparam>
        /// <param name="byteStream">A valid IMFByteStream instance.</param>
        /// <param name="buffer">An array of T that contains the data to write.</param>
        /// <param name="offset">An offset from the start of the buffer at which to begin reading the data written to the byte stream.</param>
        /// <param name="count">The number of items to write.</param>
        /// <param name="itemsWritten">Receives the number of items written.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult Write <T>(this IMFByteStream byteStream, T[] buffer, int offset, int count, out int itemsWritten) where T : struct
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("value");
            }

            if (count > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            ArraySegment <T> arraySegment = new ArraySegment <T>(buffer, offset, count);

            return(IMFByteStreamExtensions.Write <T>(byteStream, arraySegment, out itemsWritten));
        }
        /// <summary>
        /// Writes asynchronously data to a byte stream
        /// </summary>
        /// <typeparam name="T">A value type.</typeparam>
        /// <param name="byteStream">A valid IMFByteStream instance.</param>
        /// <param name="buffer">An array of T that contain the data to write.</param>
        /// <param name="offset">An index offset in buffer at which to begin storing the data read from the byte stream.</param>
        /// <param name="count">The maximum number of items to be read from the byte stream.</param>
        /// <returns>A task that represents the asynchronous write operation. The task's result contain the number of items written.</returns>
        public static Task <int> WriteAsync <T>(this IMFByteStream byteStream, T[] buffer, int offset, int count) where T : struct
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("value");
            }

            if (offset > buffer.Length)
            {
                throw new ArgumentNullException("offset");
            }

            if ((offset + count) > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            ArraySegment <T> arraySegment = new ArraySegment <T>(buffer, offset, count);

            return(IMFByteStreamExtensions.WriteAsync <T>(byteStream, arraySegment));
        }
 /// <summary>
 /// Reads data from a byte stream
 /// </summary>
 /// <param name="byteStream">A valid IMFByteStream instance.</param>
 /// <param name="buffer">A byte array that receives the data.</param>
 /// <param name="offset">An offset from the start of the buffer at which to begin storing the data read from the byte stream.</param>
 /// <param name="count">The maximum number of bytes to be read from the byte stream.</param>
 /// <param name="bytesRead">The total number of bytes read into the buffer.</param>
 /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
 public static HResult Read(this IMFByteStream byteStream, byte[] buffer, int offset, int count, out int bytesRead)
 {
     return(IMFByteStreamExtensions.Read <byte>(byteStream, buffer, offset, count, out bytesRead));
 }
 /// <summary>
 /// Writes asynchronously data to a byte stream
 /// </summary>
 /// <param name="byteStream">A valid IMFByteStream instance.</param>
 /// <param name="buffer">A byte array that contain the data to write.</param>
 /// <param name="offset">An offset from the start of the buffer at which begin the data to write to the byte stream.</param>
 /// <param name="count">The maximum number of bytes to be written to the byte stream.</param>
 /// <returns>A task that represents the asynchronous write operation. The task's result contain the number of bytes written.</returns>
 public static Task <int> WriteAsync(this IMFByteStream byteStream, byte[] buffer, int offset, int count)
 {
     return(IMFByteStreamExtensions.WriteAsync <byte>(byteStream, buffer, offset, count));
 }
 /// <summary>
 /// Writes data to a byte stream.
 /// </summary>
 /// <param name="byteStream">A valid IMFByteStream instance.</param>
 /// <param name="buffer">A byte array that contains the data to write.</param>
 /// <param name="offset">An offset from the start of the buffer at which to begin reading the data written to the byte stream.</param>
 /// <param name="count">The number of bytes to write.</param>
 /// <param name="bytesWritten">The total number of bytes write into the buffer.</param>
 /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
 public static HResult Write(this IMFByteStream byteStream, byte[] buffer, int offset, int count, out int bytesWritten)
 {
     return(IMFByteStreamExtensions.Write <byte>(byteStream, buffer, offset, count, out bytesWritten));
 }