It’s kinda odd - but there’s no standard way to copy between streams in the .net framework. Coming from a Delphi background, I’m used to being able to easily copy information from one stream to another easily.

Why? The common ancestor to all Delphi streams (TStream) includes a method that does exactly that. Here is the declaration:

function CopyFrom(Source: TStream; Count: Int64): Int64;

This allows you to copy a specified number of bytes from the current position in one stream into a target stream.

The .Net framework doesn’t have this - meaning that whenever there is a need to copy information from one stream to another (a common enough occurrence), the developer needs to roll their own.

Admittedly, the function is easy enough to implement (there is even an example buried in the help file, if you can but find it).

It just seems an oddly fundamental thing to have left out - isn’t the whole idea of a framework to supply the common stuff so you can concentrate on the things unique to your application?

Update April 2014: It took several years, but in .NET 4.0 Microsoft introduced a CopyTo method on the Stream base class. Yay!


blog comments powered by Disqus