当前位置: 首页>>代码示例>>C#>>正文


C# ICodeElement.AddChild方法代码示例

本文整理汇总了C#中ICodeElement.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeElement.AddChild方法的具体用法?C# ICodeElement.AddChild怎么用?C# ICodeElement.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICodeElement的用法示例。


在下文中一共展示了ICodeElement.AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ArrangeElement

        /// <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);
            }
        }
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:76,代码来源:RegionArranger.cs

示例2: ArrangeElement

        /// <summary>
        /// Arranges an element, delegating the responsibility to the first arranger
        /// encountered who can process the request.
        /// </summary>
        /// <param name="parentElement">Parent code element.</param>
        /// <param name="codeElement">Code element to arrange.</param>
        public void ArrangeElement(ICodeElement parentElement, ICodeElement codeElement)
        {
            bool arranged = false;

            // Region elements are ignored.  Only process their children.
            RegionElement regionElement = codeElement as RegionElement;
            if (regionElement != null)
            {
                List<ICodeElement> regionChildren = new List<ICodeElement>(regionElement.Children);
                regionElement.ClearChildren();

                foreach (ICodeElement regionChildElement in regionChildren)
                {
                    ArrangeElement(parentElement, regionChildElement);
                }
            }
            else
            {
                foreach (IElementArranger arranger in _arrangers)
                {
                    if (arranger.CanArrange(parentElement, codeElement))
                    {
                        arranger.ArrangeElement(parentElement, codeElement);
                        arranged = true;
                        break;
                    }
                }

                if (!arranged)
                {
                    if (parentElement != null)
                    {
                        parentElement.AddChild(codeElement);
                    }
                    else
                    {
                        throw new InvalidOperationException(
                            string.Format(
                            Thread.CurrentThread.CurrentCulture,
                            "Cannot arrange element of type {0} with name '{1}'.",
                            codeElement.GetType().Name,
                            codeElement.Name));
                    }
                }
            }
        }
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:52,代码来源:ChainElementArranger.cs

示例3: InsertElement

 /// <summary>
 /// Inserts the element in the code arrangement.
 /// </summary>
 /// <param name="parentElement">Parent element to insert into.</param>
 /// <param name="codeElement">Code element to insert.</param>
 public virtual void InsertElement(ICodeElement parentElement, ICodeElement codeElement)
 {
     parentElement.AddChild(codeElement);
 }
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:9,代码来源:DefaultElementInserter.cs

示例4: InsertElement

        /// <summary>
        /// Inserts the element within the parent.
        /// </summary>
        /// <param name="parentElement">Parent element to insert into.</param>
        /// <param name="codeElement">Code element to insert.</param>
        public void InsertElement(ICodeElement parentElement, ICodeElement codeElement)
        {
            GroupElement group = null;

            string groupName = GetGroupName(_groupBy.By, codeElement);

            foreach (ICodeElement childElement in parentElement.Children)
            {
                GroupElement groupElement = childElement as GroupElement;
                if (groupElement != null && groupElement.Name == groupName)
                {
                    group = groupElement;
                    break;
                }
            }

            if (group == null)
            {
                group = new GroupElement();
                group.Name = groupName;
                group.SeparatorType = _groupBy.SeparatorType;
                group.CustomSeparator = _groupBy.CustomSeparator;

                int insertIndex = parentElement.Children.Count;

                if (_groupBy.Direction != SortDirection.None)
                {
                    // Sort the groups by the attribute selected for grouping
                    for (int compareIndex = parentElement.Children.Count - 1; compareIndex >= 0;
                        compareIndex--)
                    {
                        GroupElement siblingGroup = parentElement.Children[insertIndex - 1] as GroupElement;
                        if (siblingGroup != null && siblingGroup.Children.Count > 0)
                        {
                            // This may not be the most accurate way to do this, but just compare
                            // against the first element in the sibling group.
                            ICodeElement compareElement = siblingGroup.Children[0];

                            // For nested groups, we need to drill down to find the first element.
                            while (compareElement is GroupElement && compareElement.Children.Count > 0)
                            {
                                compareElement = compareElement.Children[0];
                            }

                            // Create the element comparer if necessary
                            if (_sortComparer == null)
                            {
                                _sortComparer = new ElementComparer(_groupBy.By, _groupBy.Direction);
                            }

                            int compareValue = _sortComparer.Compare(codeElement, compareElement);

                            // System using directives should always be placed first in the file.
                            if (compareValue < 0 && (!(codeElement is UsingElement) || siblingGroup.Name != "System") ||
                                (codeElement is UsingElement && groupName == "System"))
                            {
                                insertIndex = compareIndex;
                            }
                        }
                    }
                }

                if (insertIndex < parentElement.Children.Count)
                {
                    parentElement.InsertChild(insertIndex, group);
                }
                else
                {
                    parentElement.AddChild(group);
                }
            }

            if (_innerInserter != null)
            {
                _innerInserter.InsertElement(group, codeElement);
            }
            else
            {
                group.AddChild(codeElement);
            }
        }
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:86,代码来源:GroupedInserter.cs


注:本文中的ICodeElement.AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。