Exemplo n.º 1
0
        /// <summary>
        /// 寻找所有的region,不包含层级关系
        /// </summary>
        /// <param name="classElement"></param>
        /// <returns></returns>
        public List <RegionElement> GetAllRegionsInClass(CodeElement classElement)
        {
            List <RegionElement> allRegions = new List <RegionElement>();
            int        currentLine          = classElement.StartPoint.Line - 1;
            VSTextView textView             = new VSTextView(VSTextView.ActiveTextView);

            //使用栈来寻找可能嵌套的region
            Stack <int> stack = new Stack <int>();

            while (currentLine <= classElement.EndPoint.Line)
            {
                string region = textView.GetOneLineText(currentLine);
                if (region != null)
                {
                    if (region.TrimStart().StartsWith("#region"))
                    {
                        stack.Push(currentLine);
                    }
                    if (region.TrimStart().StartsWith("#endregion"))
                    {
                        RegionElement textSpan = new RegionElement();
                        if (stack.Count != 0)
                        {
                            textSpan.StartLine  = stack.Pop();
                            textSpan.EndLine    = currentLine;
                            textSpan.Level      = stack.Count + 1;
                            textSpan.RegionName = textView.GetOneLineText(textSpan.StartLine).Trim()
                                                  .Replace("#region ", "").Replace("\r\n", "");
                            allRegions.Add(textSpan);
                        }
                    }
                }
                currentLine++;
            }

            return(allRegions);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 寻找所有的region,不包含层级关系
        /// </summary>
        /// <param name="classElement"></param>
        /// <returns></returns>
        public List<RegionElement> GetAllRegionsInClass(CodeElement classElement)
        {
            List<RegionElement> allRegions = new List<RegionElement>();
            int currentLine = classElement.StartPoint.Line - 1;
            VSTextView textView = new VSTextView(VSTextView.ActiveTextView);

            //使用栈来寻找可能嵌套的region
            Stack<int> stack = new Stack<int>();
            while (currentLine <= classElement.EndPoint.Line)
            {
                string region = textView.GetOneLineText(currentLine);
                if (region != null)
                {
                    if (region.TrimStart().StartsWith("#region"))
                    {
                        stack.Push(currentLine);
                    }
                    if (region.TrimStart().StartsWith("#endregion"))
                    {
                        RegionElement textSpan = new RegionElement();
                        if (stack.Count != 0)
                        {

                            textSpan.StartLine = stack.Pop();
                            textSpan.EndLine = currentLine;
                            textSpan.Level = stack.Count + 1;
                            textSpan.RegionName = textView.GetOneLineText(textSpan.StartLine).Trim()
                                .Replace("#region ", "").Replace("\r\n", "");
                            allRegions.Add(textSpan);
                        }
                    }
                }
                currentLine++;
            }

            return allRegions;
        }
Exemplo n.º 3
0
        private void RecursionAddChildren(RegionElement item, TreeNode node)
        {
            if (item.Children.Count>0)
            {
                foreach (RegionElement child in item.Children)
                {
                    TreeNode childNode = new TreeNode(child.RegionName);
                    childNode.Tag = child;
                    RecursionAddChildren(child, childNode);
                    node.Nodes.Add(childNode);

                }
            }
        }