SharpCifs.Std
SharpCifs.Std copied to clipboard
Examples should use `using`
Wrapping code in a using block is the standard way in .NET to free up resources.
For example, instead of the current sample code for reading a file, how about this:
Read a File:
//using System;
//using System.IO;
//using System.Text;
//using SharpCifs.Smb;
//Get target's SmbFile.
var file = new SmbFile("smb://UserName:Password@ServerIP/ShareName/Folder/FileName.txt");
//Get readable stream.
using (var readStream = file.GetInputStream()) {
//Create reading buffer.
var memStream = new MemoryStream();
//Get bytes.
((Stream)readStream).CopyTo(memStream);
}
Console.WriteLine(Encoding.UTF8.GetString(memStream.ToArray()));
hmm, Personally, the shorter the sample, the more pleasing I am. But perhaps, there are many copy and paste programmers in the world than we think. I think that you are right.
I'll update samples at a convenient time.
Using idiomatic C# is shorter in this case (no explicit call to Dispose), than the same example in the readme.