Using Reference Aliases

I recently ran across a situation where two different libraries shared identical namespaces and class names. Visual Studio complained anytime I used one of these classes that it was an ambiguous reference. I needed both libraries -- each contained some unique elements -- so I couldn't ditch one or the other. But, as I said, anytime I tried to use a class that was common (again, via the class name and namespace), I received the ambiguous reference error. This was a real problem, so say the least. However, C# provides a way to specify exactly which library (reference) you mean when you use an object that's common to two or more libraries. Simply put, you use an extern alias  statement. The concept is fairly simple: Give the reference an alias (I used the Properties windows for the reference). Add an extern alias statement, putting it before your using statements. Add a using statement, which effectively links a specific object through the extern alias statement to th

Git Fundamentals video from Visual Studio Toolbox | Channel 9

Having been TFS-only for the last 2 years, I needed to brush up on my git basics as a new project ramps up at work. The video below, from the the Visual Studio Toolbox team at Microsoft, is pretty good at covering the essentials: Git Fundamentals The video is about an hour and ten minutes long.

A virtual file system for .NET written in C# (found on Github)

For later review:

C# chars, bytes, and strings, Oh My.

Some simple code to show the conversions between the different data types: // establish a base line System. Console .WriteLine(" Testing bytes, chars, encoding, etc. "); char myChar = ' a '; byte myCharBytes = Convert.ToByte(myChar); System. Console .WriteLine(" The number of bytes in a char is 1 byte. "); System. Console .WriteLine(" The value of myCharBytes is " + myCharBytes); // the following is wrong because it converts 97 to a string of "97" string myByteString = myCharBytes.ToString(); System. Console .WriteLine(" myByteString.Length = " + myByteString.Length); System. Console .WriteLine(" myByteString = " + myByteString); // the following is correct because it converts 97 to "a" char myGoodByteChar = Convert.ToChar(myCharBytes); string myGoodByteCharString = Convert.ToString(myGoodByteChar); System. Console .WriteLine(" myGoodByteCharString = " + myGoodByteCharString); Sys

List of Visual Studio Keyboard Shortcuts

Here's a link to a great list of keyboard shortcuts for Visual Studio: 149 Shortcuts for Visual Studio 2015 (Windows) While there's no need to memorize the list (that's why someone has created a cheat sheet, after all), it certainly doesn't hurt to look over the list from time to time and try to add one more command to your repertoire.

Quick Example of System.IO.Abstractions Use

I just got on a new project and am trying from the get-go to structure all my code so that it's easily testable. Academically, that is a no-brainer. In practice, though, some chunks of code are more difficult to structure so that they're easily testable. Towards that end, I've been pushing System.IO.Abstractions again. And, to get that going I decided it was time to refresh my examples. In the code below, we see how injecting the file system into the repository ultimately allows us to write testable code. If structured correctly, then our repository requires no subsequent refactoring to run in a unit test environment versus a "real" environment even when dealing with something like the file system. Let's take a look at our code. The Console Application The console application is straightforward. We have a private method (at the bottom) that assembles and returns a mock file system. Next, we perform the following steps: We feed that mock file system