public Roslyn.Compilers.CSharp.DirectiveSyntax GetLastDirective(Func <Roslyn.Compilers.CSharp.DirectiveSyntax, bool> predicate = null) { foreach (SyntaxNodeOrToken syntaxNodeOrToken in this.ChildNodesAndTokens().Reverse()) { if (syntaxNodeOrToken.HasDirectives) { if (syntaxNodeOrToken.IsNode) { Roslyn.Compilers.CSharp.DirectiveSyntax lastDirective = syntaxNodeOrToken.AsNode().GetLastDirective(predicate); if (lastDirective != null) { return(lastDirective); } } else { Roslyn.Compilers.CSharp.SyntaxToken syntaxToken = syntaxNodeOrToken.AsToken(); for (int index = syntaxToken.LeadingTrivia.Count - 1; index >= 0; --index) { Roslyn.Compilers.CSharp.SyntaxTrivia syntaxTrivia = syntaxToken.LeadingTrivia[index]; if (syntaxTrivia.IsDirective) { Roslyn.Compilers.CSharp.DirectiveSyntax directiveSyntax = (Roslyn.Compilers.CSharp.DirectiveSyntax)syntaxTrivia.GetStructure(); if (predicate == null || predicate(directiveSyntax)) { return(directiveSyntax); } } } } } } return((Roslyn.Compilers.CSharp.DirectiveSyntax)null); }
public Roslyn.Compilers.CSharp.DirectiveSyntax GetFirstDirective(Func <Roslyn.Compilers.CSharp.DirectiveSyntax, bool> predicate = null) { foreach (SyntaxNodeOrToken syntaxNodeOrToken in this.ChildNodesAndTokens()) { if (syntaxNodeOrToken.HasDirectives) { if (syntaxNodeOrToken.IsNode) { Roslyn.Compilers.CSharp.DirectiveSyntax firstDirective = syntaxNodeOrToken.AsNode().GetFirstDirective(predicate); if (firstDirective != null) { return(firstDirective); } } else { foreach (Roslyn.Compilers.CSharp.SyntaxTrivia syntaxTrivia in syntaxNodeOrToken.AsToken().LeadingTrivia) { if (syntaxTrivia.IsDirective) { Roslyn.Compilers.CSharp.DirectiveSyntax directiveSyntax = (Roslyn.Compilers.CSharp.DirectiveSyntax)syntaxTrivia.GetStructure(); if (predicate == null || predicate(directiveSyntax)) { return(directiveSyntax); } } } } } } return((Roslyn.Compilers.CSharp.DirectiveSyntax)null); }