Developing on Staxmanade

NuGet Project Uncovered: Guard

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Guard is one of the MANY projects coming out of the netfx project. (HOLY NUGET there’s a ton of these).

If you’re not familiar with the netfx project, you should become acquainted with it. Daniel Cazzulino (of Moq fame) and others have created an awesome set of add-on functionality to the .Net framework through these NuGet packages

Back to the Guard package:

Many .Net developers tend to write their guard clauses as such…

image_thumb3_thumb

One problem with this is that if you were to rename the “value” parameter you have to make sure you rename the magic string “value” in the guard check.

The Guard package offers a solution that is a little more resilient to these types of rename issues as its usage will automatically either get renamed, or if you don’t you will get a compiler error.

The below test shows an example of its usage.

image_thumb1111_thumb

If you run that test, you’ll see a nice exception message.
image_thumb6_thumb[1]