GSF.IO.BinaryStreamBase.Seek C# (CSharp) Method

Seek() public method

When overridden in a derived class, sets the position within the current stream.
An I/O error occurs. The stream does not support seeking, such as if the stream is constructed from a pipe or console output. Methods were called after the stream was closed.
public Seek ( long offset, SeekOrigin origin ) : long
offset long A byte offset relative to the parameter.
origin SeekOrigin A value of type indicating the reference point used to obtain the new position.
return long
        public long Seek(long offset, SeekOrigin origin)
        {
            if (!CanSeek)
                throw new NotSupportedException();

            switch (origin)
            {
                case SeekOrigin.Begin:
                    Position = offset;
                    break;
                case SeekOrigin.Current:
                    Position += offset;
                    break;
                case SeekOrigin.End:
                    Position = Length + offset;
                    break;
                default:
                    throw new InvalidEnumArgumentException("origin", (int)origin, typeof(SeekOrigin));
            }
            return Position;
        }

Usage Example

コード例 #1
0
 /// <summary>
 /// When overridden in a derived class, sets the position within the current stream.
 /// </summary>
 /// <returns>
 /// The new position within the current stream.
 /// </returns>
 /// <param name="offset">A byte offset relative to the <paramref name="origin"/> parameter. </param><param name="origin">A value of type <see cref="T:System.IO.SeekOrigin"/> indicating the reference point used to obtain the new position. </param><exception cref="T:System.IO.IOException">An I/O error occurs. </exception><exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception><filterpriority>1</filterpriority>
 public override long Seek(long offset, SeekOrigin origin)
 {
     return(BaseStream.Seek(offset, origin));
 }