RE: Issue ID: 363 Add ability to get consolidated list of broken rules for an entire object graph

RE: Issue ID: 363 Add ability to get consolidated list of broken rules for an entire object graph

Old forum URL: forums.lhotka.net/forums/t/7648.aspx


chrduf posted on Thursday, September 17, 2009

Hi Rocky

 

We have implemented this function in our environment and would like to contribute the function for the community.  This would be added to BusinessBase…

 

#if !(SILVERLIGHT)

        public Csla.Validation.BrokenRulesCollection GetAllBrokenRules()

        {

            Csla.Validation.BrokenRulesCollection list = Csla.Validation.BrokenRulesCollection.CreateCollection();

            if (FieldManager.HasFields)

            {

                // add broken rules at the root object level

                list.Merge("root_" + this.GetHashCode().ToString(), BrokenRulesCollection);

 

                // get children objects of the current instance

                foreach (object child in this.FieldManager.GetChildren())

                {

                    // see if child implements ICPBrokenRules - if it does then you can call the GetAllBrokenRules method

                    if ((child is ICPBrokenRules) && (child as Csla.Core.IEditableBusinessObject != null) && (((Csla.Core.IEditableBusinessObject)child).IsValid == false))

                    {

                        list.Merge("child_" + child.GetHashCode().ToString(), ((ICPBrokenRules)child).GetAllBrokenRules());

                    }

                    else

                    {

                        // see if the object is a Csla.Core.IEditableCollection - then it should be of type CPBusinessListBase

                        if (child is Csla.Core.IEditableCollection)

                        {

                            // go and call the same function for every child in the collection since they must be of type IEditable

                            // determine if the object is of type CPBusinessListBase - if so, cast it to the corresponding type,

 

                            foreach (object nefew in (IEnumerable)child)

                            {

                                if (nefew is ICPBrokenRules)

                                {

                                    list.Merge("child_" + this.GetHashCode().ToString() + "_" + child.GetHashCode().ToString(), (nefew as ICPBrokenRules).GetAllBrokenRules());

                                }

                            }

                        }

                    }

 

                }

            }

            return list;

        }

 

#endif

 

Thanks

 

Chris Dufour
MVP ASP.NET, MCAD, IBM Certified Database Associate - DB2 UDB V8.1
Software Architect

Compuware Corporation

(905) 886-7700 Ext. 4489

chris.dufour@compuware.com

 

 

 

 

Copyright (c) Marimer LLC