public static bool IsParentOf(this ModelItem item, ModelItem child) { if (null == item) { throw FxTrace.Exception.ArgumentNull("item"); } if (null == child) { throw FxTrace.Exception.ArgumentNull("child"); } bool isParent = false; child.GetParentEnumerator(p => { isParent = ModelItem.Equals(p, item); return(!isParent); }).LastOrDefault(); return(isParent); }
internal static ModelItem FindCommonVariableScope(ModelItem scope1, ModelItem scope2) { if (null == scope1 || null == scope2) { throw FxTrace.Exception.AsError(new ArgumentNullException(null == scope1 ? "scope1" : "scope2")); } var scope1List = scope1.GetParentEnumerator().Where(p => null != VariableHelper.GetVariableCollection(p)).ToList(); var scope2List = scope2.GetParentEnumerator().Where(p => null != VariableHelper.GetVariableCollection(p)).ToList(); if (null != VariableHelper.GetVariableCollection(scope1)) { scope1List.Insert(0, scope1); } if (null != VariableHelper.GetVariableCollection(scope2)) { scope2List.Insert(0, scope2); } if (scope1 == scope2) { return scope1List.FirstOrDefault(); } return scope1List.Intersect(scope2List).FirstOrDefault(); }
internal static ModelItem FindRootVariableScope(ModelItem element) { if (null == element) { throw FxTrace.Exception.ArgumentNull("element"); } ModelItem result = element.GetParentEnumerator().Where(p => null != VariableHelper.GetVariableCollection(p)).LastOrDefault(); return result; }