Esempio n. 1
0
 public Roslyn.Compilers.CSharp.SyntaxToken FindToken(int position, Func <Roslyn.Compilers.CSharp.SyntaxTrivia, bool> findInsideTrivia)
 {
     Roslyn.Compilers.CSharp.SyntaxToken syntaxToken = this.FindToken(position, false);
     if (findInsideTrivia != null)
     {
         Roslyn.Compilers.CSharp.SyntaxTrivia syntaxTrivia = new Roslyn.Compilers.CSharp.SyntaxTrivia();
         TextSpan span = syntaxToken.Span;
         if (position < span.Start && syntaxToken.HasLeadingTrivia)
         {
             syntaxTrivia = Roslyn.Compilers.CSharp.SyntaxNode.GetTriviaThatContainsPosition(syntaxToken.LeadingTrivia, position);
         }
         else if (position >= span.End && syntaxToken.HasTrailingTrivia)
         {
             syntaxTrivia = Roslyn.Compilers.CSharp.SyntaxNode.GetTriviaThatContainsPosition(syntaxToken.TrailingTrivia, position);
         }
         if (syntaxTrivia.HasStructure && findInsideTrivia(syntaxTrivia))
         {
             syntaxToken = syntaxTrivia.GetStructure().FindTokenInternal(position);
         }
     }
     return(syntaxToken);
 }
Esempio n. 2
0
 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);
 }