Esempio n. 1
0
        void RetrieveRegions(ICompilationUnit cu, NRefactory.Parser.SpecialTracker tracker)
        {
            for (int i = 0; i < tracker.CurrentSpecials.Count; ++i)
            {
                NRefactory.PreprocessingDirective directive = tracker.CurrentSpecials[i] as NRefactory.PreprocessingDirective;
                if (directive != null)
                {
                    if (directive.Cmd.Equals("#region", StringComparison.OrdinalIgnoreCase))
                    {
                        int deep = 1;
                        for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j)
                        {
                            NRefactory.PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as NRefactory.PreprocessingDirective;
                            if (nextDirective != null)
                            {
                                switch (nextDirective.Cmd.ToLowerInvariant())
                                {
                                case "#region":
                                    ++deep;
                                    break;

                                case "#end":
                                    if (nextDirective.Arg.Equals("region", StringComparison.OrdinalIgnoreCase))
                                    {
                                        --deep;
                                        if (deep == 0)
                                        {
                                            cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DomRegion(directive.StartPosition, nextDirective.EndPosition)));
                                            goto end;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        end :;
                    }
                }
            }
        }
Esempio n. 2
0
        private void RetrieveRegions(ICompilationUnit cu, NRefactory.Parser.SpecialTracker tracker)
        {
            for (int i = 0; i < tracker.CurrentSpecials.Count; ++i)
            {
                NRefactory.PreprocessingDirective directive = tracker.CurrentSpecials[i] as NRefactory.PreprocessingDirective;
                if (directive != null)
                {
                    if (directive.Cmd == "#region")
                    {
                        int deep = 1;
                        for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j)
                        {
                            NRefactory.PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as NRefactory.PreprocessingDirective;
                            if (nextDirective != null)
                            {
                                switch (nextDirective.Cmd)
                                {
                                case "#region":
                                    ++deep;
                                    break;

                                case "#endregion":
                                    --deep;
                                    if (deep == 0)
                                    {
                                        cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DomRegion(directive.StartPosition, nextDirective.EndPosition)));
                                        goto end;
                                    }
                                    break;
                                }
                            }
                        }
                        end :;
                    }
                }
            }
        }