I have a class that contains a reference to a parent object
class Joint
{
public Joint Parent { get; private set; }
}
Given a single Joint
I can enumerate all the parent objects in the chain with
public IEnumerable<Joint> ThisAndParentJoints
{
get
{
Joint joint=this;
while(joint!=null)
{
yield return joint;
joint=joint.Parent;
}
}
}
Is there a way to do the above using a single LINQ statement?
NOTE: I can find all the child joints given a List<Joint> all
public IEnumerable<Joint> ChildJoints {
get { return all.Where((jnt) => jnt.Parent==this); }
}