Finding the topmost object in the parentage

Finding the topmost object in the parentage

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


PaulNakata posted on Friday, May 01, 2009

I'm in the process of converting an app that was using CSLA 1.5 to Csla 3.5, and I'm running into some issues involving object parentage.

I have some code that used to loop through the objects to get the "parentmost" object. We had to do this because we don't know if the object being passed to us is a parent or child object until we use it.

Originally, the code looked like this:
CSLA.Core.IDirtyObject b = bb;

while ((b != null) && (b.Parent != null))
    {
     b = b.Parent;
    }
But I can't figure out a way to make this work using 3.5...  doing this:
BusinessBase<T> b = bb;
while ((b != null) && (b.Parent != null))
    {
        b = b.Parent;
    }
Gives an error trying to access the Parent property ("Cannot access internal property 'Parent' here").

Any suggestions?

RockfordLhotka replied on Friday, May 01, 2009

Parent is a protected property, not public. If you want external code to walk up the object graph, you'll need to expose a public Parent property (or equivalent) in your own class structure.

If you have your own custom base classes between the CSLA base classes and your business classes this is pretty easy to do. And I do recommend creating such base classes as a general rule, because that's the primary extensibility model for CSLA.

skagen00 replied on Friday, May 01, 2009

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

Not 100% sure this is what you're looking for, but it sounds similar to something that I was looking to do in the thread above.

PaulNakata replied on Tuesday, May 05, 2009

skagen00:
http://forums.lhotka.net/forums/thread/25961.aspx Not 100% sure this is what you're looking for, but it sounds similar to something that I was looking to do in the thread above.


A combination of this and Rocky's suggestion to use intermediary classes worked perfectly. Thank you both for your help!

Copyright (c) Marimer LLC