MvcValidatorToolkit/ValidationSet.cs
/// <summary>
/// Validates the rules for the implementing validator against the specified values
/// collection.
/// </summary>
Validates the rules for the implementing validator against the specified values
collection.
Validates the rules for the implementing validator against the specified values collection .
public bool Validate(NameValueCollection values)
		{
			IsValid = true;
			ErrorMessages = new NameValueCollection();
			InvalidElements = new List<string>();
			if(values == null)
				throw new ArgumentNullException("values");
			else
				Values = values;
			UpdateFields();
			List<Validator> validators = new List<Validator>();
			foreach(Validator validator in GetValidators().ToArray())
				validators.AddRange(validator.Translate());
			foreach(Validator validator in validators.ToArray())
			{
				InitialzeValidator(validator);
				if(!validator.Validate(Values, this, InvalidElements))
				{
					IsValid = false;
					foreach(string element in validator.ErrorMessages.AllKeys)
					{
						if(ErrorMessages.ContainsKey(element)==false)
							ErrorMessages.Add(element, validator.ErrorMessages[element]);
					}
					UpdateInvalidElements(validator.InvalidElements.ToArray());
				}
			}
			try
			{
				OnValidate();
			}
			catch(ValidatorException e)
			{
				IsValid = false;
				if(!string.IsNullOrEmpty(e.InvalidElement) && !InvalidElements.Contains(e.InvalidElement))
				{
					ErrorMessages.Add(e.InvalidElement, e.Message);
					UpdateInvalidElements(new string[] { e.InvalidElement });
				}
			}
			return IsValid;
		}
public bool Validate ( NameValueCollection values ) { IsValid = true ; ErrorMessages = new NameValueCollection ( ) ; InvalidElements = new List < string > ( ) ; if ( values == null ) throw new ArgumentNullException ( " " ) ; else Values = values ; UpdateFields ( ) ; List < Validator > validators = new List < Validator > ( ) ; foreach ( Validator validator in GetValidators ( ) . ToArray ( ) ) validators . AddRange ( validator . Translate ( ) ) ; foreach ( Validator validator in validators . ToArray ( ) ) { InitialzeValidator ( validator ) ; if ( ! validator . Validate ( Values , this , InvalidElements ) ) { IsValid = false ; foreach ( string element in validator . ErrorMessages . AllKeys ) { if ( ErrorMessages . ContainsKey ( element ) == false ) ErrorMessages . Add ( element , validator . ErrorMessages [ element ] ) ; } UpdateInvalidElements ( validator . InvalidElements . ToArray ( ) ) ; } } try { OnValidate ( ) ; } catch ( ValidatorException e ) { IsValid = false ; if ( ! string . IsNullOrEmpty ( e . InvalidElement ) && ! InvalidElements . Contains ( e . InvalidElement ) ) { ErrorMessages . Add ( e . InvalidElement , e . Message ) ; UpdateInvalidElements ( new string [ ] { e . InvalidElement } ) ; } } return IsValid ; }
Validates the rules for the implementing validator against the specified values
collection.
Validates the rules for the implementing validator against the specified values collection .
// Copies the element value from the Values collection into field member of the  // implementing validation set using reflection // Get defined validators and translates them into final list of validators // Excutes the validation process for each validator // Call a final and overall validation method for the validation set and  // catch all ValidatorExceptions
values
NameValueCollection