Esempio n. 1
0
        private ValidationResultsCollection Validate()
        {
            ValidationResultsCollection result = DoValidation();

            if (result == null)
            {
                Throw.InvalidOperationException(Res.ComponentModelDoValidationNull);
            }

            bool newIsValid          = !result.HasErrors;
            bool raiseIsValidChanged = newIsValid != lastIsValid;

            isValid = lastIsValid = newIsValid;

            ValidationResultsCollection lastResult = cachedValidationResults;
            bool raiseValidationResultsChanged     = lastResult?.SequenceEqual(result) != true;

            cachedValidationResults = result.ToReadOnly();

            if (raiseIsValidChanged)
            {
                OnPropertyChanged(new PropertyChangedExtendedEventArgs(!newIsValid, newIsValid, nameof(IsValid)));
            }
            if (raiseValidationResultsChanged)
            {
                OnPropertyChanged(new PropertyChangedExtendedEventArgs(lastResult, result, nameof(ValidationResults)));
            }

            return(result);
        }
Esempio n. 2
0
        /// <inheritdoc />
        protected internal override void OnPropertyChanged(PropertyChangedExtendedEventArgs e)
        {
            if (e == null)
            {
                Throw.ArgumentNullException(Argument.e);
            }

            // Invalidating cached validation results if an affected property has changed.
            if (isValid != null && AffectsModifiedState(e.PropertyName))
            {
                isValid = null;
                cachedValidationResults = null;
            }

            base.OnPropertyChanged(e);
        }