while looking at Shrinkr's source code (we all review other project's source code to learn, right??? :) ) I noticed the following kewl code .. (abbreviated by me, below)
public virtual Foo Foo
{
get;
set
{
Check.Argument.IsNotNull(value, "value");
// then do something.
}
}
Notice the fluent way they check for arguments? Nice :)
(source: cherrythian.com)
So .. checking the code, they have some custom class that does this...
public static class Check
{
public static class Argument
{
public static void IsNotNull(object parameter,
string parameterName)
{ ... }
public static void IsNotNullOrEmpty(string parameter,
string parameterName)
{ ... }
.... etc ....
}
Are there any common frameworks out there?
gem install netFluentCheck ?
:)
I ended up using CuttingEdge Conditions, found on Codeplex.
eg.
// Check all preconditions:
Condition.Requires(id, "id")
.IsNotNull() // throws ArgumentNullException on failure
.IsInRange(1, 999) // ArgumentOutOfRangeException on failure
.IsNotEqualTo(128); // throws ArgumentException on failure
nice :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With