determine object's collection

  • Thread starter Thread starter Jure Bogataj
  • Start date Start date
J

Jure Bogataj

Hello!

This may be a silly question, but anyway:

If I have collection / list of objects:

public class MyCollection : List<MyObject>
{
}

public class MyObject
{
...
}

And then somewhere in the code I add object to the collection:
....
MyCollection col = new MyCollection()
MyObject obj = new MyObject()
col.Add(obj);

Is it possible now to determine which is obj's parent collection (sth like:
obj.?ParentCollection?) or must I manually track parent collections (e.g.
new MyObject(col) or sth like that). I know object can participate in more
than one collection at the same time (or not) so this may not be possible at
all?


Thanks in advance!

Best regards,
Jure
 
And then somewhere in the code I add object to the collection:
...
MyCollection col = new MyCollection()
MyObject obj = new MyObject()
col.Add(obj);

Is it possible now to determine which is obj's parent collection (sth like:
obj.?ParentCollection?) or must I manually track parent collections (e.g.
new MyObject(col) or sth like that). I know object can participate in more
than one collection at the same time (or not) so this may not be possible at
all?

You'd have to have specific support in MyObject for this - an object
doesn't have any inherent idea of whether it's part of another
collection or not.

Jon
 
Back
Top