Custom Validator

Jul 7, 2009 at 12:26 PM

Yet another idea. I'm inspired today. ;)

This one is an necessity that I have in one of my projects.

Some times I have to make validation on my database and to do this I use nhibernate to fetch one object and then I test someting in this object. If I have the custom Validator I'll pass the nhibernate query for exemple to the validator and use the extensions to validate the way I want.

I don't figured out how to do this yet, this is just an Idea.

Coordinator
Jul 21, 2009 at 2:10 PM

We already did think about about an extensions interface and provide some support for custom validation rules. Check out:

http://tnvalidate.codeplex.com/Wiki/View.aspx?title=Extending%20TNValidate&ANCHOR#rules

Does that help? Or do you need, rather than extending an existing validator, to write one that accepts your own type of object? In that case, you maybe can use an extension method to add an overload of the That method on Validate to get it working as you wish...your own validator should inherit from ValidatorBase.

Hope this helps,

Jonathan

Jul 21, 2009 at 2:24 PM

Yes, what I need is an new validator.

I'll create another validator inherited from ValidatorBase and post an Patch here to you.

I'm thinking to make an Linq Validator...

Coordinator
Jul 22, 2009 at 2:22 PM

I think for the next release we'll document how to create a new validator as another means of extending TNValidate. I'm glad we didn't do it before now, since ValidatorBase changed today a bit, but I think with this latest change I'm happy we've got something good enough to move forward with and keep as a stable interface (I wasn't completely happy with some code duplication we had in 1.0, which I've addressed today...it also reduces some boilerplate you'd need to write your own validator and have Not() work on it).