本文整理汇总了C#中SeekOrigin类的典型用法代码示例。如果您正苦于以下问题:C# SeekOrigin类的具体用法?C# SeekOrigin怎么用?C# SeekOrigin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SeekOrigin类属于命名空间,在下文中一共展示了SeekOrigin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Seek
public override long Seek(long offset, SeekOrigin origin)
{
var len = Length;
switch (origin)
{
case SeekOrigin.Begin:
_position = offset;
break;
case SeekOrigin.Current:
_position += offset;
break;
case SeekOrigin.End:
_position = len - offset;
break;
}
if (_position > len)
{
_position = len;
}
else if (_position < 0)
{
_position = 0;
}
return _position;
}
示例2: Seek
public override Int64 Seek(Int64 offset, SeekOrigin origin) {
Contract.Requires((int)origin >= 0);
Contract.Requires((int)origin <= 2);
Contract.EnsuresOnThrow<System.IO.IOException>(true, @"An I/O error occurred.");
return default(Int64);
}
示例3: Seek
public void Seek(long offset, SeekOrigin origin)
{
int totalCount;
if (this._typeIsDocument)
totalCount = this._db.Statistics.CountOfDocuments;
else
totalCount = this._db.Statistics.CountOfIndexes;
if (offset > totalCount)
{
throw new
ArgumentException(
"Offset cannot be greater than the number of " + (_typeIsDocument ? "documents" : "indexes")
);
}
if (origin == SeekOrigin.Begin)
{
// starting from Beginning with an index 0, the current offset
// has to be advanced to offset - 1
_currentOffset = _currentOffset - 1;
}
else if (origin == SeekOrigin.End)
{
// starting from the end which is numRows - 1, the current
// offset is so much less than numRows - 1
_currentOffset = totalCount - 1 - _currentOffset;
}
else
{
// calculate from the previous value of current offset
// advancing forward always
_currentOffset += Convert.ToInt32(offset);
}
}
示例4: Seek
public override long Seek(long offset, SeekOrigin origin)
{
lock (underlyingStream)
{
return underlyingStream.Seek(offset, origin);
}
}
示例5: Seek
/// <summary>
/// Sets the position within the current stream.
/// </summary>
/// <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>
/// <returns>The new position within the current stream.</returns>
public override long Seek(long offset, SeekOrigin origin)
{
if (origin == SeekOrigin.Begin)
offset += m_baseOffset;
return base.Seek(offset, origin) - m_baseOffset;
}
示例6: Seek
/// <summary>
/// Seek
/// </summary>
/// <param name="offset">offset</param>
/// <param name="origin">origin</param>
/// <returns>zero</returns>
public override long Seek(long offset, SeekOrigin origin)
{
ReadAttempt();
long temp = -1;
switch (origin)
{
// seek beyond the FormatVersion
case SeekOrigin.Begin:
temp = offset;
break;
case SeekOrigin.Current:
checked { temp = Position + offset; }
break;
case SeekOrigin.End:
checked { temp = Length + offset; }
break;
}
if (temp < 0)
throw new ArgumentException(SR.Get(SRID.SeekNegative));
checked { BaseStream.Position = temp + _dataOffset; }
return temp;
}
示例7: Seek
public override long Seek(
long offset,
SeekOrigin origin
)
{
return _baseStream.Seek(offset, origin);
}
示例8: Seek
public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
{
if (offset != Position)
return base.Seek(offset, origin);
}
break;
case SeekOrigin.Current:
{
if (offset != 0)
return base.Seek(offset, origin);
}
break;
case SeekOrigin.End:
{
if (offset != Length - Position)
return base.Seek(offset, origin);
}
break;
}
return Position;
}
示例9: Seek
public override long Seek(long offset, SeekOrigin origin)
{
int oldPosition = _Position;
switch (origin)
{
case SeekOrigin.Begin:
_Position = (int)offset;
break;
case SeekOrigin.Current:
_Position += (int)offset;
break;
case SeekOrigin.End:
_Position = _Length + (int)offset;
break;
}
if (_Position >= _Length)
{
_Position = oldPosition;
throw new IOException("");
}
return _Position;
}
示例10: Seek
public override long Seek (long offset, SeekOrigin origin)
{
if (origin == SeekOrigin.Begin)
return Position = offset;
else
throw new NotSupportedException ();
}
示例11: Seek
public override long Seek(long offset, SeekOrigin origin)
{
this.ValidateSeekable();
long beginOffset = this.GetBeginOffset(offset, origin);
if ((beginOffset < this._stream.Position) &&
(beginOffset >= this._stream.Position - this._alignmentLength))
{
this._alignmentOffset = (int)(beginOffset - this._stream.Position);
}
else if (beginOffset == this._stream.Position)
{
this._alignmentOffset = 0;
this._alignmentLength = 0;
}
else
{
long alignedOffset = this.GetAlignedValue(beginOffset);
if (this._stream.Position != alignedOffset)
{
this._stream.Seek(alignedOffset, SeekOrigin.Begin);
}
this._alignmentOffset = (int)(beginOffset - alignedOffset);
this._alignmentLength = 0;
}
return beginOffset;
}
示例12: Seek
public override long Seek(long offset, SeekOrigin origin)
{
if (offset != 0L)
{
if ((offset < 0L) || ((origin != SeekOrigin.Current) && (!this.CanSeekFromBeginning || (origin != SeekOrigin.Begin))))
{
throw new ArgumentException();
}
if (this.CheckWriteOrFinished())
{
return 0L;
}
this.CanSeekFromBeginning = false;
while (offset >= (this.size - this.offset))
{
offset -= this.size - this.offset;
this.WriteEvent.Reset();
this.ReadEvent.Set();
if (this.CheckWriteOrFinished())
{
return 0L;
}
}
this.offset += (int) offset;
}
return 0L;
}
示例13: Seek
public void Seek(int offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
while (offset < 0)
offset += this._stringLength;
while (offset > this._stringLength)
offset -= this._stringLength;
while (offset > this.ReadedBuffer.Length)
{
this.Read();
}
this._position = offset;
break;
case SeekOrigin.Current:
this.Seek(offset + this._position, SeekOrigin.Begin);
break;
case SeekOrigin.End:
this.Seek(-offset, SeekOrigin.Begin);
break;
}
}
示例14: Seek
public long Seek(long offset, SeekOrigin origin)
{
// no such thing as abstract in c...
// we need a vTable?
return __Stream_Seek(this, offset, origin);
}
示例15: MoveCursor
/// <summary>
/// Move the cursor.
/// </summary>
/// <param name="origin">Which origin to use for calculating the new
/// cursor position.</param>
/// <param name="offsetFromOrigin">The offset to apply,
/// relative to the specified origin.</param>
/// <param name="offsetFromPreviousPosition">On success, receives the
/// resulting offset moved from the previous position.</param>
/// <returns>True on success; false if the movement could not be made.
/// </returns>
public bool MoveCursor(SeekOrigin origin, int offsetFromOrigin, out int offsetFromPreviousPosition)
{
int startingIndex;
switch (origin)
{
case SeekOrigin.Begin:
startingIndex = 0;
break;
case SeekOrigin.Current:
startingIndex = CursorIndex;
break;
case SeekOrigin.End:
startingIndex = _buffer.Length;
break;
default:
throw new ArgumentOutOfRangeException(nameof(origin));
}
var newIndex = startingIndex + offsetFromOrigin;
if ((newIndex < 0) || (newIndex > _buffer.Length))
{
offsetFromPreviousPosition = 0;
return false;
}
offsetFromPreviousPosition = newIndex - CursorIndex;
CursorIndex = newIndex;
return true;
}