CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

BrokenRulesCollection for Root and Children, ISupportBrokenRules

rated by 0 users
This post has 4 Replies | 1 Follower

Not Ranked
Posts 2
JeroenEikmans Posted: Sat, Oct 4 2008 1:52 PM
Hi,

I wanted to create a 'generic' way of accessing the BrokenRulesCollection of an editable root and all of it's children. I'm overriding the BrokenRulesCollection of the root. This is roughly the idea:


        public override BrokenRulesCollection BrokenRulesCollection
        {
            get
            {
                BrokenRulesCollection brokenRules = BrokenRulesCollection.CreateCollection();

                // merge the brokenrules of this
                brokenRules.Merge("??", base.BrokenRulesCollection);

                // merge the brokenrules of the children
                List<object> children = this.FieldManager.GetChildren();
                foreach (object child in children)
                {
                    // child could be an editable object
                    if (child is IEditableBusinessObject)
                    {
                        ISupportBrokenRules editableBaseEntity = child as ISupportBrokenRules;
                        if (editableBaseEntity != null)
                            // recursive call to BrokenRulesCollection
                            brokenRules.Merge("??", editableBaseEntity.BrokenRulesCollection);
                    }

                    // child could be an editable collection
                    if (child is IEditableCollection)
                    {
                        IList list = child as IList;
                        for (int index = 0; index < list.Count; index++)
                        {
                            ISupportBrokenRules editableBaseEntity = list[index] as ISupportBrokenRules;
                            if (editableBaseEntity != null)
                                // recursive call to BrokenRulesCollection
                                brokenRules.Merge("{0}.{1}[{2}]".FormatWith("??", "??", index), editableBaseEntity.BrokenRulesCollection);
                        }
                    }
                }

                return brokenRules;
            }
        }


You see there is a cast to ISupportBrokenRules because the GetChildren returns a list of objects. The definition is:

    public interface ISupportBrokenRules : ITrackStatus
    {
        BrokenRulesCollection BrokenRulesCollection { get; }
    }


It would be nice to have the ISupportBrokenRules interface defined by the CSLA framework and not by me. Or is there an interface that already does this?

Maybe there's a smarter way to achieve what I'm doing here alltogether. Any opinions?

thanks,
Jeroen
Top 10 Contributor
Posts 1,244

I have posted a complete working solution to this before:
http://forums.lhotka.net/forums/post/7444.aspx

It may be a bit out of date now that CSLA has added so much extensibility. But you can review it for ideas.

HTH

Joe

 

 

Not Ranked
Posts 2
Thanks for your link to the other post. Your solution builds a complete BrokenRulesCollection for all invalid children, including the ones in editable collections. That's nice, I can use that.

For now I only want to build a BrokenRulesCollection that is a 'result' of a call to the IsValid property of the root, so including only the invalid children and the first invalid children in editable collections.

When the root is not valid, I just want to check the BrokenRulesCollection of the root to see why the root is not valid.

thanks,
Jeroen
Top 200 Contributor
Posts 35
FrankM replied on Tue, Oct 14 2008 12:41 PM
How about 
foreach ( var child in children)
{
       if (child is BusinessBase)
       {
             brokenRules.Merge("??", ((BusinessBase)child).BrokenRulesCollection);
       }
}
I am doing the similar stuff.

Top 50 Contributor
Posts 112
JohnB replied on Wed, Oct 15 2008 8:31 AM
Jeroen,

Like Joe, I too posted a workable solution with an example that I did some time ago.

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

John
Page 1 of 1 (5 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems