我目前正在编写一个缓存BaseStream.Position
和BaseStream.Length
属性的 BinaryReader。这是我到目前为止所拥有的:
public class FastBinaryReader
{
BinaryReader reader;
public long Length { get; private set; }
public long Position { get; private set; }
public FastBinaryReader(Stream stream)
{
reader = new BinaryReader(stream);
Length = stream.Length;
Position = 0;
}
public void Seek(long newPosition)
{
reader.BaseStream.Position = newPosition;
Position = newPosition;
}
public byte[] ReadBytes(int count)
{
if (Position + count >= Length)
Position = Length;
else
Position += count;
return reader.ReadBytes(count);
}
public void Close()
{
reader.Close();
}
}
我不想提供Length
andPosition
属性,而是想创建一个BaseStream
属性,允许我将我的Position
andLength
属性公开为FastBinaryReader.BaseStream.Position
and FastBinaryReader.BaseStream.Length
,这样我现有的代码将与原始BinaryReader
类保持兼容。
我该怎么做呢?