I have a collection:
List> dependencyHierarchy;
The first item in pair is some object (item) and the
I would make this easier on myself by storing the dependencies of an Item within the Item itself:
public class Item
{
private List- m_Dependencies = new List
- ();
protected AddDependency(Item _item) { m_Dependencies.Add(_item); }
public Item()
{
}; // eo ctor
public List
- Dependencies {get{return(m_Dependencies);};}
} // eo class Item
Then, given this you can implement a custom Sort delegate for List that sorts based on whether the given Item is contained within the other's list of dependencies:
int CompareItem(Item _1, Item _2)
{
if(_2.Dependencies.Contains(_1))
return(-1);
else if(_1.Dependencies.Contains(_2))
return(1);
else
return(0);
}