protected override CodeFoldingResult GetCodeFoldingResult(out int firstErrorOffset) {
      var document = codeEditor.TextEditor.Document;
      var result = new CodeFoldingResult();

      try {
        var reader = new XmlTextReader(document.CreateReader()) { XmlResolver = null };
        var foldings = CreateNewFoldings(document, reader, out firstErrorOffset);
        result.FoldingData = foldings.ToList();
      } catch (XmlException) {
        firstErrorOffset = 0;
        result.FoldingData = new List<NewFolding>();
      }

      return result;
    }
    protected override CodeFoldingResult GetCodeFoldingResult(out int firstErrorOffset) {
      var document = codeEditor.TextEditor.Document;
      var result = new CodeFoldingResult();

      try {
        var foldingContext = new CSharpCodeFoldingContext(document);
        var v = new FoldingVisitor();
        v.document = foldingContext.Document;
        foldingContext.SyntaxTree.AcceptVisitor(v);
        result.FoldingData = v.foldings.OrderBy(x => x.StartOffset).ToList();

        var firstError = foldingContext.SyntaxTree.Errors.FirstOrDefault();
        firstErrorOffset = firstError != null
          ? foldingContext.Document.GetOffset(firstError.Region.Begin)
          : int.MaxValue;
      } catch {
        // ignore exceptions thrown during code folding
        firstErrorOffset = int.MaxValue;
      }

      return result;
    }
        protected virtual void ApplyCodeFoldingData(CodeFoldingResult codeFoldingResult, int firstErrorOffset)
        {
            var foldings = codeFoldingResult.FoldingData;

            foldingManager.UpdateFoldings(foldings, firstErrorOffset);
        }
 protected virtual void ApplyCodeFoldingData(CodeFoldingResult codeFoldingResult, int firstErrorOffset) {
   var foldings = codeFoldingResult.FoldingData;
   foldingManager.UpdateFoldings(foldings, firstErrorOffset);
 }