Applying Fluent Interface. Part II – fluent validation.
In of the podcasts on Dimecast.Net Derik Whittaker has shown very smart way to address object validation with Fluent interface.
First I couldn’t help myself but notice that “Painfulway Validation” could be replaced with a yield constructs (picked up from ScottGu’s tutorial):
public static IEnumerable<string> Validate (HostEntry hostEntry)
{
if (string.isNullOrEmpty(hostEntry.FirstName))
yield return "First Name is null";
if (string.isNullOrEmpty(hostEntry.LastName))
yield return "Last Name is null";
etc...
Maybe it is still painful to read but obviously less verbose. But anyway that construct is still to be replaced by Derek’s smart implementation.
No comments:
Post a Comment