示例#1
0
        /// <summary>
        /// Arranges the child element.
        /// </summary>
        /// <param name="codeElement">The code element.</param>
        /// <param name="childElement">The child element.</param>
        private void ArrangeChildElement(ICodeElement codeElement, ICodeElement childElement)
        {
            //
            // Region elements are ignored.  Only process their children.
            //
            RegionElement regionElement = childElement as RegionElement;

            if (regionElement != null)
            {
                List <ICodeElement> regionChildren = new List <ICodeElement>(regionElement.Children);
                regionElement.ClearChildren();

                foreach (ICodeElement regionChildElement in regionChildren)
                {
                    _childrenArranger.ArrangeElement(codeElement, regionChildElement);
                }
            }
            else
            {
                _childrenArranger.ArrangeElement(codeElement, childElement);
            }
        }
示例#2
0
        /// <summary>
        /// Arranges the specified code element into the parent.
        /// </summary>
        /// <param name="parentElement">Parent element to arrange within.</param>
        /// <param name="codeElement">Code element to arrange.</param>
        public void ArrangeElement(ICodeElement parentElement, ICodeElement codeElement)
        {
            InitializeChildrenArranger();

            if (codeElement != null)
            {
                RegionElement region = null;

                string regionName        = _regionConfiguration.Name;
                bool   directivesEnabled = _regionConfiguration.DirectivesEnabled;

                foreach (ICodeElement childElement in parentElement.Children)
                {
                    RegionElement regionElement = childElement as RegionElement;
                    if (regionElement != null && regionElement.Name == regionName)
                    {
                        region = regionElement;
                        break;
                    }
                }

                if (region == null)
                {
                    region      = new RegionElement();
                    region.Name = regionName;
                    region.DirectivesEnabled = directivesEnabled;

                    if (parentElement.Children.Count == 0)
                    {
                        parentElement.AddChild(region);
                    }
                    else
                    {
                        //
                        // Determine where to insert the new region
                        //
                        int insertIndex  = 0;
                        int compareIndex = _levelRegions.IndexOf(region.Name);

                        for (int siblingIndex = 0;
                             siblingIndex < parentElement.Children.Count;
                             siblingIndex++)
                        {
                            RegionElement siblingRegion = parentElement.Children[siblingIndex]
                                                          as RegionElement;
                            if (siblingRegion != null)
                            {
                                insertIndex = siblingIndex;

                                int siblingCompareIndex = _levelRegions.IndexOf(siblingRegion.Name);
                                if (compareIndex <= siblingCompareIndex)
                                {
                                    break;
                                }
                                else
                                {
                                    insertIndex++;
                                }
                            }
                            else
                            {
                                insertIndex++;
                            }
                        }

                        parentElement.InsertChild(insertIndex, region);
                    }
                }

                _childrenArranger.ArrangeElement(region, codeElement);
            }
        }