Beispiel #1
0
        private static ModelElement GetCompartmentElementFirstParent(ModelElement modelElement)
        {
            // Get the domain class associated with model element.
            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass != null)
            {
                // A element is only considered to be in a compartment if it participates in only 1 embedding relationship
                // This might be wrong for some models

                if (domainClass.AllEmbeddedByDomainRoles.Count == 1)
                {
                    // Get a collection of all the links to this model element
                    // Since this is in a compartment there will only be one
                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetAllElementLinks(modelElement);
                    if (links.Count == 1)
                    {
                        // Get the model element participating in the link that isn't the current one
                        // That will be the parent
                        // Probably there is a better way to achieve the same result
                        foreach (ModelElement linkedElement in links[0].LinkedElements)
                        {
                            if (!modelElement.Equals(linkedElement))
                            {
                                return(linkedElement);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        private static ModelElement GetCompartmentElementFirstParentElement(this ModelElement modelElement)
        {
            // Get the domain class associated with model element.

            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass?.AllEmbeddedByDomainRoles?.Count == 1)
            {
                DomainRoleInfo roleInfo = domainClass.AllEmbeddedByDomainRoles[0];

                // Get a collection of all the links to this model element
                // Since this is in a compartment there should be at least one
                // There can be only one.

                ElementLink elementLink = roleInfo.GetElementLinks(modelElement)?.FirstOrDefault();
                return(elementLink?.LinkedElements?.FirstOrDefault(e => !modelElement.Equals(e)));
            }

            return(null);
        }
        private static ModelElement GetCompartmentElementFirstParentElement(this ModelElement modelElement)
        {
            // Get the domain class associated with model element.
            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass != null)
            {
                // A element is only considered to be in a compartment if it participates in only 1 embedding relationship
                // This might be wrong for some models

                if (domainClass.AllEmbeddedByDomainRoles.Count == 1)
                {
                    DomainRoleInfo roleInfo = domainClass.AllEmbeddedByDomainRoles[0];

                    // Get a collection of all the links to this model element
                    // Since this is in a compartment there should be at least one
                    // There can be only one.
                    if (roleInfo != null)
                    {
                        ElementLink link = roleInfo.GetElementLinks(modelElement).FirstOrDefault();

                        // Get the model element participating in the link that isn't the current one
                        // That will be the parent
                        // Probably there is a better way to achieve the same result
                        return(link?.LinkedElements?.FirstOrDefault(linkedElement => !modelElement.Equals(linkedElement)));
                    }
                }
            }

            return(null);
        }