System.IO.Stream 的完全兼容替换作为扩展
Complete compatible replacement of System.IO.Stream as an extension
我需要使用包装实际流的服务进行文件传输,并决定将其实现为完全兼容的 System.IO.Stream
替代,覆盖所有方法和属性。我打算将它用作常规流,中间的服务执行 IO。是否有我可以参考的 IO.Stream
的生命周期文档?没找到,可能是我用错关键词了
这是 MSDN 上的基础知识:
Notes to Implementers
When you implement a derived class of Stream, you must provide implementations for the Read and Write methods. The asynchronous methods ReadAsync, WriteAsync, and CopyToAsync use the synchronous methods Read and Write in their implementations. Therefore, your implementations of Read and Write will work correctly with the asynchronous methods.
The default implementations of ReadByte and WriteByte create a new single-element byte array, and then call your implementations of Read and Write. When you derive from Stream, we recommend that you override these methods to access your internal buffer, if you have one, for substantially better performance. You must also provide implementations of CanRead, CanSeek, CanWrite, Flush, Length, Position, Seek, and SetLength.
Do not override the Close method, instead, put all the Stream cleanup logic in the Dispose method.
我需要使用包装实际流的服务进行文件传输,并决定将其实现为完全兼容的 System.IO.Stream
替代,覆盖所有方法和属性。我打算将它用作常规流,中间的服务执行 IO。是否有我可以参考的 IO.Stream
的生命周期文档?没找到,可能是我用错关键词了
这是 MSDN 上的基础知识:
Notes to Implementers
When you implement a derived class of Stream, you must provide implementations for the Read and Write methods. The asynchronous methods ReadAsync, WriteAsync, and CopyToAsync use the synchronous methods Read and Write in their implementations. Therefore, your implementations of Read and Write will work correctly with the asynchronous methods.
The default implementations of ReadByte and WriteByte create a new single-element byte array, and then call your implementations of Read and Write. When you derive from Stream, we recommend that you override these methods to access your internal buffer, if you have one, for substantially better performance. You must also provide implementations of CanRead, CanSeek, CanWrite, Flush, Length, Position, Seek, and SetLength.
Do not override the Close method, instead, put all the Stream cleanup logic in the Dispose method.