A Flexible Guard Class (Update)

I’ve decided to rename the root class for the checks to “Bouncer” (http://en.wiktionary.org/wiki/bouncer : “A member of security personnel employed by bars, nightclubs, etc to maintain order and deal with patrons who cause trouble.”). To check all registered and attribute based rules of a parameter, one line of code per parameter is enough:

Bouncer.ForCheckData(() => customer).Assert();

Also you can now query the bouncer for rule violations without causing exceptions:

var res = Bouncer.ForMessages(() => saveBusinessObject).Assert();
foreach (var result in res.Results)
  Console.WriteLine(result);

The exceptions have been improved to include the name of the parameter and the name of the property of that object which causes the violation. A violation will now always create a “RuleValidationException” which inherits from “ArgumentException” (that way exception handlers catching “ArgumentException” will work, but you also can catch specificly the exceptions of rule violations).
The fluent interface has been improved, so you can now implement additional ways to check the rules – exception throwing and creation of a list of violations have been implemented, but possible you want just central logging of specific information. To do that, you need to

The functionality is now inside the Sem.Sync project under LGPL (you can freely use it in free and commercial products, but if you modify it, your modification is also bound to LGPL). A sample project also has been included.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Sylvio's Infobox

Aktuelle Themen rund um SQL Server, BI, Windows, ...

Meredith Lewis

Professional Digital Portfolio

Vittorio Bertocci

Just another WordPress.com weblog

ScottGu's Blog

Just another WordPress.com weblog

AJ's blog

Thoughts and informations I think worthwhile to share...

Outlawtrail - .NET Development

Architecture & Design

SDX eXperts Flurfunk

Just another WordPress.com weblog

%d bloggers like this: