You can use Call the extension method. Simply put, transformation of an instance of the code to use StreamUtil and transform the tool as simple classes. The following code uses we have suggested that a new "syntax" to call the CopyTo. I say "new" in fact it does not new because it is and we have been using exactly the same as calling an instance method syntax.
Code:
WebRequest request = WebRequest.Create ("http://mysite.com");
Using (WebResponse response = request.GetResponse ())
using (Stream responseStream = response.GetResponseStream ())
using (FileStream output = File.Create ("response123.dat"))
{
responseStream.CopyTo (output);
}
In the above code, at least it looks like we let response flow to complete the copying operation. StreamUtil fact remains behind the completion of the actual work, but more natural reading of the code. Compiler behind the scenes is really only CopyTo call will be transferred to the right StreamUtil.CopyTo calls, and pass responseStream as a method of the first parameter.
Bookmarks