//----------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Validation { using System; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Runtime; [Fx.Tag.XamlVisible(false)] public class ValidationResults { ReadOnlyCollection allValidationErrors; ReadOnlyCollection errors; ReadOnlyCollection warnings; bool processedAllValidationErrors; public ValidationResults(IList allValidationErrors) { if (allValidationErrors == null) { this.allValidationErrors = ActivityValidationServices.EmptyValidationErrors; } else { this.allValidationErrors = new ReadOnlyCollection(allValidationErrors); } } public ReadOnlyCollection Errors { get { if (!this.processedAllValidationErrors) { ProcessAllValidationErrors(); } return this.errors; } } public ReadOnlyCollection Warnings { get { if (!this.processedAllValidationErrors) { ProcessAllValidationErrors(); } return this.warnings; } } void ProcessAllValidationErrors() { if (this.allValidationErrors.Count == 0) { this.errors = ActivityValidationServices.EmptyValidationErrors; this.warnings = ActivityValidationServices.EmptyValidationErrors; } else { IList warningsList = null; IList errorsList = null; for (int i = 0; i < this.allValidationErrors.Count; i++) { ValidationError violation = this.allValidationErrors[i]; if (violation.IsWarning) { if (warningsList == null) { warningsList = new Collection(); } warningsList.Add(violation); } else { if (errorsList == null) { errorsList = new Collection(); } errorsList.Add(violation); } } if (warningsList == null) { this.warnings = ActivityValidationServices.EmptyValidationErrors; } else { this.warnings = new ReadOnlyCollection(warningsList); } if (errorsList == null) { this.errors = ActivityValidationServices.EmptyValidationErrors; } else { this.errors = new ReadOnlyCollection(errorsList); } } this.processedAllValidationErrors = true; } } }