29 Jan
2012

NuGet Project Uncovered: Guard

Category:UncategorizedTag: :

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 it?s 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]

3 thoughts on “NuGet Project Uncovered: Guard

  1. That’s an interesting variation on the early binding INotifyPropertyChanged implementation that I’ve seen used a lot (and use myself).

Comments are closed.

Find me

RSS
Facebook
LinkedIn

Disclaimer

The opinions and content expressed here are my own and not those of my employer.