コード例 #1
0
        private static string?GetNameOfInvokedExpression(ISyntaxFacts syntaxFacts, SyntaxNode invokedExpression)
        {
            if (syntaxFacts.IsSimpleMemberAccessExpression(invokedExpression))
            {
                return(syntaxFacts.GetIdentifierOfSimpleName(syntaxFacts.GetNameOfMemberAccessExpression(invokedExpression)).ValueText);
            }

            if (syntaxFacts.IsIdentifierName(invokedExpression))
            {
                return(syntaxFacts.GetIdentifierOfSimpleName(invokedExpression).ValueText);
            }

            return(null);
        }
コード例 #2
0
        private static bool IsValidFormatMethod(ISyntaxFacts syntaxFacts, SyntaxNode expression)
        {
            // When calling string.Format(...), the expression will be MemberAccessExpressionSyntax
            if (syntaxFacts.IsSimpleMemberAccessExpression(expression))
            {
                var nameOfMemberAccessExpression = syntaxFacts.GetNameOfMemberAccessExpression(expression);
                return(!syntaxFacts.IsGenericName(nameOfMemberAccessExpression) &&
                       syntaxFacts.GetIdentifierOfSimpleName(nameOfMemberAccessExpression).ValueText
                       == (nameof(string.Format)));
            }

            // When using static System.String and calling Format(...), the expression will be
            // IdentifierNameSyntax
            if (syntaxFacts.IsIdentifierName(expression))
            {
                return(syntaxFacts.GetIdentifierOfSimpleName(expression).ValueText
                       == (nameof(string.Format)));
            }

            return(false);
        }
コード例 #3
0
        protected static string?GetNameOfType(SyntaxNode?typeNode, ISyntaxFacts syntaxFacts)
        {
            if (syntaxFacts.IsQualifiedName(typeNode))
            {
                return(GetNameOfType(syntaxFacts.GetRightSideOfDot(typeNode), syntaxFacts));
            }
            else if (syntaxFacts.IsIdentifierName(typeNode))
            {
                return(syntaxFacts.GetIdentifierOfSimpleName(typeNode).ValueText);
            }

            return(null);
        }
 protected bool ValuePatternMatches(TExpressionSyntax expression)
 {
     if (_valuePattern.IsToken)
     {
         return(_syntaxFacts.IsIdentifierName(expression) &&
                _syntaxFacts.AreEquivalent(
                    _valuePattern.AsToken(),
                    _syntaxFacts.GetIdentifierOfSimpleName(expression)));
     }
     else
     {
         return(_syntaxFacts.AreEquivalent(
                    _valuePattern.AsNode(), expression));
     }
 }