Some suggestions

Aug 7, 2010 at 9:35 AM

Hi Steven,

Thanks for your great library. It save me a lot of time. When using it, some ideas come out to me. In some of the String validatior methods, it will be great if there is an another param 'IgnoreCase', e.g. Condition.Requires(str, "str").StartsWith("abc", true); // the true means igore cases.

Another one is that, in addition to current specific validators, may be we can add a more generic validator. That may looks like

a) Condition.Requires(str, "str").That(s => some validation on s);

b) Condition.Requires(some validation on s, "Value should xxx");

Thanks & regards,

Wayne

Coordinator
Aug 7, 2010 at 11:39 AM
Edited Aug 7, 2010 at 12:22 PM

Dear Wayne,

Thank you for using Conditions. About your suggestion about validating strings the following:

The validation methods for strings contain an overload that accepts a System.StringComparison enum, that allows you to exactly specify how the strings must be compared. You can ignore the case be writing the following:

Condition.Requires(str, "str").StartWith("abc", StringComparison.OrdinalIgnoreCase);

While it is a more verbose than using a boolean, it in fact does a better job in describing its intent. I hope this works for you.

About you suggestion about the generic validator, the following:

The framework currently contains several overloads named 'Evaluate` that do exactly this. There's an overload excepting a boolean, and there is an overload excepting an Expression<Func<T, bool>> (a lambda). Here are two examples:

Condition.Requires(str, "str").Evaluate(s => s == null || s.Length > 100);
Condition.Requires(str, "str").Evaluate(s == null || s.Length > 100, "Value should xxx");

I hope this works for you.

If there are any questions about this, or other suggestions, please keep them coming.

Aug 9, 2010 at 2:47 AM

Sorry, its my bad, I have missed the overloads of the string validator methods and the Evaluate method. They are just what I want.

Thanks & regards,

Wayne