Don't Repeat Yourself to validate parameters by using CuttingEdge.Conditions
Edit
From my experience, if you are writing a decent piece of code, there is always a need to validate input parameters. Often time it will be realized when writing unit tests as the validate test is a must in the security / QA perspective and it is always the easiest kind of unit tests, so why not do those easy tasks and tell others your code is working and backed by unit tests?
However, when you have written enough validation code, you will find those validation codes are very similar. Most of the time the only different is the variable type and name and you can copy the code snippet everywhere or create a static function for it. And when you start a new project, the issues of validation code came back again. In the past I will just open an old project and copy the code snippet or static function I have written to the new project. But today I discovered "CuttingEdge.Conditions" which is a library with loads of static function to validate your parameters and throw proper exception accordingly. It support C# and VB and you can get it in Nuget!
Here is a simple example in C#
Further Read:
CuttingEdge.Conditions - Home
Get the library from NuGet : http://www.nuget.org/packages/CuttingEdge.Conditions
However, when you have written enough validation code, you will find those validation codes are very similar. Most of the time the only different is the variable type and name and you can copy the code snippet everywhere or create a static function for it. And when you start a new project, the issues of validation code came back again. In the past I will just open an old project and copy the code snippet or static function I have written to the new project. But today I discovered "CuttingEdge.Conditions" which is a library with loads of static function to validate your parameters and throw proper exception accordingly. It support C# and VB and you can get it in Nuget!
Here is a simple example in C#
Further Read:
CuttingEdge.Conditions - Home
Get the library from NuGet : http://www.nuget.org/packages/CuttingEdge.Conditions
Don't Repeat Yourself to validate parameters by using CuttingEdge.Conditions
Reviewed by DF
on
7:15:00 PM
Rating: