Smart Code

Reinventing the Validation Wheel

A comment by SaltySeaDog over on my post Easier property validation with dynamic in C# 4 got me thinking.

You have some special use case that requires you to reinvent that wheel?
There are several wheels around - http://fluentvalidation.codeplex.com/ just to name one... or are you just prototyping for it's own sake?

Easier property validation with dynamic in C# 4

High quality input validation is essential to many, if not all systems that we write. It doesn't matter whether we're validating user input in a WPF or Silverlight application, checking data transfer objects passed into a service layer or verifying the information in a JSON packet submitted by REST, validation is essential.

Lately, I've been working with a bunch of code that looks like this:

Elegant.Data

Over on The Codeface, Mark Rendle has a very interesting idea: Simple.Data

To achieve the same task with Simple.Data, you can do this:

var db = Database.Open(); // Connection specified in config.
var user = db.Users.FindByNameAndPassword(name, password);

MoreLINQ

I just stumbled across this - a very useful extension LINQ library called MoreLinq.

The list of extensions that it provides includes some real gems:

Avoiding Null Checks

Courtesy of a link tweet from Ayende and a blog entry on DevTalk.net, here's an interesting way to avoid null checks in code: the .With() extension method.

Syndicate content