public static ITECObject FindChild(this IRelatable parent, Guid guid) { foreach (ITECObject child in parent.GetDirectChildren()) { if (child.Guid == guid) { return(child); } else if (child is IRelatable childRel) { var found = childRel.FindChild(guid); if (found != null) { return(found); } } } return(null); }
/// <summary> /// Returns all objects of type T which exist as a direct descendant /// </summary> /// <typeparam name="T"></typeparam> /// <param name="relatable"></param> /// <returns></returns> public static List <T> GetAll <T>(this IRelatable relatable) { List <T> list = new List <T>(); if (relatable is T typedObj) { list.Add(typedObj); } foreach (var item in relatable.GetDirectChildren()) { if (item is IRelatable rel) { list.AddRange(GetAll <T>(rel)); } else if (item is T x) { list.Add(x); } } return(list); }
private static void getObjectPath(IRelatable parent, ITECObject descendant, List <ITECObject> path) { var children = parent.GetDirectChildren(); if (children.Contains(descendant)) { path.Add(descendant); path.Add(parent); } else { foreach (var child in children.OfType <IRelatable>()) { int before = path.Count; getObjectPath(child, descendant, path); if (path.Count > before) { path.Add(parent); break; } } } }