ValidationResults.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Validation / ValidationResults.cs / 1305376 / ValidationResults.cs

                            //------------------------------------------------------------------------------ 
// 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;
 
        internal 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; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK