Broken Rules... Again

Broken Rules... Again

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


Brette.Net posted on Thursday, March 05, 2009

Hello All,

I know it has been beaten to death on this forum. However it seems that there is no real 'standard' solution to getting a list of all broken rules i.e. Root and Children. Correct me if I am wrong but it seems the only options are as follows.

1. Write some reflection to traverse the object graph and collect all the broken rules. *do not like this at all*

2. Put hooks in every Root object to return its child broken rules. This is simple enough however it is just another thing you need to keep track of and keep up to date as your domain model matures.

I am using CSLA 3.5 and it seems to me that this should be built into the framework. After all with the new Child_DataPortal and the FieldDataManager the framework already has a collection of child objects. FieldDataManager.GetChildren(). It strikes me as odd that this is not leveraged to get the broken rules also.

In any case here is what I have done. Can anyone validate or poke holes in the method...I basically created an extension method on BusinessBase....

 public static string GetBrokenRuleString(this BusinessBase businessObject)
        {
            //Precondition Check
            DBC.Check(businessObject == null, new ArgumentNullException("businessObject", "Parameter data cannot be null."));

            string errorMessage = string.Empty;
            IDataErrorInfo errorInfo;

            //retrun if valid
            if (businessObject.IsValid)
            {
                return errorMessage;
            }

            //Get root rules
            if(!businessObject.IsSelfValid)
            {
                errorInfo = businessObject;
                errorMessage += errorInfo.Error;
            }

            //Lets look at children
            Type businessObjectType = businessObject.GetType();
            PropertyInfo property = businessObjectType.GetProperty("FieldManager", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            FieldDataManager fieldDataManager = (FieldDataManager)property.GetValue(businessObject, null);
            List children = fieldDataManager.GetChildren();

            //Call on children
            for(int i = 0; i );
            }

            return errorMessage;
        }

JohnB replied on Thursday, March 05, 2009

Brette.Net,

I created a sample application some time ago that I believe can help you. It's in VB but you should have no problem with it. Let me know if you have any questions.

http://forums.lhotka.net/forums/thread/21880.aspx

Note: I did this using CSLA 3.0.3.

John


rfcdejong replied on Friday, November 06, 2009

BrokenRules is indeed just the BrokenRules of the business object itself, it would be nice to have the complete object graph available.

I noticed an wishlist issue, but it has a high priority for over 200+ days?
http://www.lhotka.net/cslabugs/edit_bug.aspx?id=363

Copyright (c) Marimer LLC