I would like to be able to say something like:

    PersonValidator : ValidationDef<Person>{
        PersonValidator(){
            Define(p=>p.Name).Required();
        }
    }

where Required is equivalent to

            Define(p=>p.Name).NotNullable().And.NotEmpty();

I'm sure this has come up before, that NotNullAndNotEmpty() will not
make whitespace ("   ") invalid although it seems at first blush like
it would. Even though once you know that chaining together
NotNull.And.NotEmpty is certainly easy enough, it could be argued that
Required() would be clearer.

I'm really more interested here in how to extend existing constraints
though. I though maybe an extension like the one below would be the
way to go but am stuck as to how to write it properly:

    public static class StringConstraintExtensions
    {
        public static IChainableConstraint<IStringConstraints>
Required(this IStringConstraints definition, string value) {
            return definition.NotNullable().And.NotEmpty(); // just
the idea but useless
        }
    }

It compiles but isn't usable. Is an extension like this the best way
to go? How can I make it work?

Thanks,
Berryl

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to