The Daily WTF
Robert has inherited a .NET application. It’s a big-ball-of-mud, full of monstrous classes of thousands of lines and no coherent purpose, complete with twenty constructors.
It’s ugly and messy, but it’s mostly just generically bad. This method, however, is a lot of bad choices in very few lines.
/// <summary> /// TODO implement !!! /// </summary> /// <param name=”file”>The file.</param> /// <returns></returns> public static Bitmap WriteFileFromByte(byte[] file) { Bitmap retVal = null; using (MemoryStream ms = new MemoryStream(file)) { retVal = new Bitmap(ms); } return retVal; }
We start with a TODO, one of my “favorite” comments. The method is called WriteFileFromByte, but that’s exactly what doesn’t happen.
Instead, this converts a byte array into a MemoryStream, and then creates a Bitmap off of that stream. That’s actually all fine. We need to convert the byte array into a stream so that the Bitmap class can ingest it.
So,
To read the full article click on the 'post' link at the top.