/// <summary> /// Finds dependent elements (in model or in diagram) /// </summary> /// <param name="diagram">reference to a diagram when lookup should be restrected to a diagram. /// pass <code>null</code> if lookup should be performed in the whole model</param> /// <param name="element">element</param> /// <param name="dependency">type of dependency</param> /// <param name="dependentElements">collection where to add dependent elements</param> /// <param name="transitive">when true, lookup is transitive (dependent elements of dependent elements ...)</param> public static void GetDependentElements(Diagram diagram, Element element, EDependency dependency, ref List <Element> dependentElements, bool transitive) { if (element is Class && (dependency & EDependency.Class_Association) == EDependency.Class_Association) { foreach (Association association in ((Class)element).Assocations) { if (!dependentElements.Contains(association)) { if ((diagram == null || IsInDiagram(diagram, association)) && !dependentElements.Contains(association)) { dependentElements.Add(association); if (transitive) { GetDependentElements(diagram, association, dependency, ref dependentElements, true); } } } } } if (element is Class && (dependency & EDependency.Class_Generalization) == EDependency.Class_Generalization) { foreach (Generalization generalization in ((Class)element).Specifications) { if (!dependentElements.Contains(generalization)) { if ((diagram == null || IsInDiagram(diagram, generalization))) { dependentElements.Add(generalization); if (transitive) { GetDependentElements(diagram, generalization, dependency, ref dependentElements, true); } } } } foreach (Generalization generalization in ((Class)element).Generalizations) { if (!dependentElements.Contains(generalization)) { if ((diagram == null || IsInDiagram(diagram, generalization))) { dependentElements.Add(generalization); if (transitive) { GetDependentElements(diagram, generalization, dependency, ref dependentElements, true); } } } } } if ((dependency & EDependency.Element_ElementComment) == EDependency.Element_ElementComment) { foreach (Comment comment in element.Comments) { if (!dependentElements.Contains(comment)) { if ((diagram == null || IsInDiagram(diagram, comment))) { dependentElements.Add(comment); if (transitive) { GetDependentElements(diagram, comment, dependency, ref dependentElements, true); } } } } } //if ((dependency & EDependency.FullConnections) == EDependency.FullConnections) //{ // if (element is Association) // { // foreach (AssociationEnd end in ((Association)element).Ends) // { // if (!dependentElements.Contains(end.Class)) // { // dependentElements.Add(end.Class); // if (transitive) // GetDependentElements(diagram, end.Class, dependency, ref dependentElements, true); // } // } // } // if (element is Generalization) // { // Class general = ((Generalization)element).General; // if (!dependentElements.Contains(general)) // { // dependentElements.Add(general); // if (transitive) // GetDependentElements(diagram, general, dependency, ref dependentElements, true); // } // Class specific = ((Generalization)element).Specific; // if (!dependentElements.Contains(specific)) // { // dependentElements.Add(specific); // if (transitive) // GetDependentElements(diagram, specific, dependency, ref dependentElements, true); // } // } //} }
/// <summary> /// Finds dependent elements in <paramref name="diagram"/> for all elements in <paramref name="elements"/>. /// </summary> /// <param name="elements">collection of elements for which dependent elements will be /// returned</param> /// <param name="diagram">diagram where dependent elements are searched</param> /// <param name="dependency">type of dependencies</param> /// <returns><see cref="ElementDependencies"/></returns> public static ElementDependencies FindElementDependenciesInDiagram(IList <Element> elements, Diagram diagram, EDependency dependency) { return(FindElementDependencies(elements, diagram, dependency)); }
/// <summary> /// Finds dependent elements in <paramref name="diagram"/> or in whole model /// for all elements in <paramref name="elements"/>. /// </summary> /// <param name="elements">collection of elements for which dependent elements will be /// returned</param> /// <param name="diagram">diagram where dependent elements are searched, when set to <code>null</code> /// lookup will be performed in the whole model</param> /// <param name="dependency">type of dependencies</param> /// <returns><see cref="ElementDependencies"/></returns> private static ElementDependencies FindElementDependencies(IList <Element> elements, Diagram diagram, EDependency dependency) { ElementDependencies dependencies = new ElementDependencies(); foreach (Element element in elements) { List <Element> dep = new List <Element>(); GetDependentElements(diagram, element, dependency, ref dep, true); dep.RemoveAll(dependentElement => elements.Contains(dependentElement)); if (dep.Count > 0) { dependencies.Flags[element] = false; dependencies[element] = dep; } } return(dependencies); }
/// <summary> /// Finds dependent elements in model for all elements in <paramref name="elements"/>. /// </summary> /// <param name="elements">collection of elements for which dependent elements will be /// returned</param> /// <param name="dependency">type of dependency</param> /// <returns><see cref="ElementDependencies"/></returns> public static ElementDependencies FindElementDependenciesInModel(IList <Element> elements, EDependency dependency) { return(FindElementDependencies(elements, null, dependency)); }