Exemple #1
0
 private static SyntaxTriviaList ConvertTriviaList(this SyntaxTriviaList csTriviaList)
 {
     return(new SyntaxTriviaList()
            .AddRange(csTriviaList
                      .Select(_ => _.ConvertTrivia())
                      .Where(_ => !_.IsKind(CS.SyntaxKind.None))));
 }
Exemple #2
0
 public static string GetDocumentation(SyntaxTriviaList trivia) =>
 trivia.Select(i => i.GetStructure())
 .OfType <DocumentationCommentTriviaSyntax>()
 .FirstOrDefault()?.Content.ToString()
 .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
 .Select(s => s.Trim())
 .Select(s => s.StartsWith("///") ? s.Remove(0, 3).Trim() : s)
 .JoinWithDelimiter(Environment.NewLine);
Exemple #3
0
        private ICollection <Trivia> ProcessTrivia(SyntaxTriviaList triviaList)
        {
            var triviaModelList = triviaList.Select(n => new Trivia(
                                                        value: n.ToFullString(),
                                                        type: n.CSharpKind().ToString()
                                                        )).ToList();

            return(triviaModelList);
        }
Exemple #4
0
        private SyntaxTriviaList AlterIndent(SyntaxTriviaList leadTrivia)
        {
            var whitespaces = leadTrivia
                              .Select((trivia, i) => new
            {
                Trivia = trivia,
                Index  = i
            })
                              .Where(o => o.Trivia.IsKind(SyntaxKind.WhitespaceTrivia))
                              .ToList();

            foreach (var whitespace in whitespaces)
            {
                var trivia = whitespace.Trivia.ToFullString();
                leadTrivia = leadTrivia
                             .RemoveAt(whitespace.Index)
                             .Insert(whitespace.Index, _subtract
                                                ? Whitespace(trivia.Substring(0, Math.Max(trivia.Length - _indent.Length, 0)))
                                                : Whitespace(trivia + _indent));
            }
            return(leadTrivia);
        }