Hey The answer it's called Constraint Validator Context.
You can see some code of example of how to manage even multiples messages for the same property https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Validator/src/NHibernate.Validator.Tests/ConstraintContext/MemberValidation/PasswordValidator.cs And for Entity Validation, example here: https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Validator/src/NHibernate.Validator.Tests/ConstraintContext/EntityValidation/PasswordValidator2.cs You can even disable the default message, but, be sure to add another message replacing the default one, otherwise if no-messages, ends in a *valid* case. Cheers On Wed, Aug 19, 2009 at 7:12 PM, The Bread <[email protected]>wrote: > > Hello, > > I am using NHibernate.Validator 1.2.0.2001 with the 2.1GA of > Nhibernate. I am creating a custom class level validator and related > attribute which I am using to validate some logic before allowing the > object to be persisted. I want to update the default error message > with details found during this validation but can't seem to figure out > how to dynamically update the message property. Below is what I have > at the moment. Any help would be greatly appreciated. > > > [AttributeUsage(AttributeTargets.Class)] > [ValidatorClass(typeof(SectionInstanceValidator))] > public class SectionInstanceAttribute : Attribute, IRuleArgs > { > private string message = string.Empty; > public string Message > { > get { return message; } > set { message = value; } > } > } > > public class SectionInstanceValidator : IValidator > { > public bool IsValid(object value, > IConstraintValidatorContext constraintValidatorContext) > { > if (value is Section) > { > string message = String.Empty; > var section = value as Section; > var numbers = section.SectionNumbers; > var formats = > Globals.BLL.Generic.GetAll<MasterSpecFormat>(); > > //Verify all MasterSpecFormats have been defined > foreach (var item in formats) > { > if (!numbers.Select(o => > o.MasterSpecFormat).Contains(item)) > { > if (message == > String.Empty) > message += item.Name; > else > message += ", " + item.Name; > } > } > if (!String.IsNullOrEmpty(message)) > { > //This is the dynamic message I want to return > with the validation error. > message = "Section number missing for " + > message; > return false; > } > else > return true; > } > else > return false; > } > } > > > Thanks, > Chris > > > -- Dario Quintana http://darioquintana.com.ar --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
