Suggestion - Overload for RuleHander with Lamda Expression.

Suggestion - Overload for RuleHander with Lamda Expression.

Old forum URL: forums.lhotka.net/forums/t/7166.aspx


Vinodonly posted on Thursday, June 25, 2009

This suggestion is based on the new property declaring syntax where we can pass a lamda expression..

We can get a overload for rulehandler which accepts 2 parameters i.e.

1. Lamda Expression
2. Error Description

Then we can write code like this..

ValidationRules.AddRule(BO => BO.ReadProperty(StartedProperty) BO.ReadProperty(EndedProperty) ,
"Start date can't be after end date")

This will check the expression passed and if result is false then set the error message to the passed text. Which means that apart from the new overload, it should have a default implementation to which this can be routed.

Additionally, when setting error message, default implementation should use string.format and supply e.propertyname,

So the calling code can set error message like this "{0} not valid"


Vinodonly replied on Thursday, June 25, 2009

Taking it a step further..

If we can have a overload with only one lamda expression, this expression should route to common method which returns a bool value for the result and in the ref or out parameter the error msg.

Advantage of this is then common rules don't need to use reflection.

RockfordLhotka replied on Thursday, June 25, 2009

This is a good idea. I think someone mentioned it once before as well, though I'm not sure. In any case, I put it into the wish list so it doesn't get lost.

Copyright (c) Marimer LLC