|
-
Dec 17th, 2007, 06:33 AM
#1
Thread Starter
PowerPoster
Get all parent/childs
I am trying to get all the parents and its children objects from an object. I need to basically keep travelling through it from a single object i have. so..
object has:
=====
entities
I need to go through the object's entities, and its entities etc.... until it gets to the root entity of the object, then work its way downwards because I need to check for uniqueness of an entity
how can I do this using recursion?
-
Dec 17th, 2007, 08:39 AM
#2
Re: Get all parent/childs
You use GetType to get an object's type. You use GetProperties to get a type's properties. You use GetValue to get a property's value. And so on, and so on, and so on...
-
Dec 17th, 2007, 09:05 AM
#3
Thread Starter
PowerPoster
Re: Get all parent/childs
sorry. my question was not that clear
basically I want to go through each and every single parent/children from the given object
how can i get to the "root" parent from a child entity?
-
Dec 17th, 2007, 05:24 PM
#4
Re: Get all parent/childs
 Originally Posted by Techno
how can i get to the "root" parent from a child entity?
You wouldn't, unless the "child" has some property that refers to the "parent". For instance, consider this:
CSharp Code:
public class Class1
{
private Class2 someField;
public Class2 SomeProperty
{
get
{
return someField;
}
set
{
someField = value;
}
}
}
public class Class2
{
//...
}
CSharp Code:
Class1 c1 = new Class1();
Class2 c2 = new Class2();
c1.SomeProperty = c2;
Now, the Class2 object has no reference to the Class1 object. It has no idea the Class1 object even exists. How could you possibly get to c1 from c2?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|