private static IdentifierNameSyntax GetIdentifierNameFromExpression(ExpressionSyntax expression)
        {
            switch (expression?.Kind())
            {
            case SyntaxKind.IdentifierName:
            {
                return((IdentifierNameSyntax)expression);
            }

            case SyntaxKind.SimpleMemberAccessExpression:
            {
                var memberAccess = (MemberAccessExpressionSyntax)expression;

                if (memberAccess.Expression?.Kind() == SyntaxKind.ThisExpression)
                {
                    SimpleNameSyntax name = memberAccess.Name;

                    if (name.IsKind(SyntaxKind.IdentifierName))
                    {
                        return((IdentifierNameSyntax)name);
                    }
                }

                break;
            }
            }

            return(null);
        }
Exemple #2
0
        private static IdentifierNameSyntax GetIdentifierName(ExpressionSyntax expression)
        {
            if (expression != null)
            {
                SyntaxKind kind = expression.Kind();

                if (kind == SyntaxKind.IdentifierName)
                {
                    return((IdentifierNameSyntax)expression);
                }
                else if (kind == SyntaxKind.SimpleMemberAccessExpression)
                {
                    var memberAccess = (MemberAccessExpressionSyntax)expression;

                    if (memberAccess.Expression?.IsKind(SyntaxKind.ThisExpression) == true)
                    {
                        SimpleNameSyntax name = memberAccess.Name;

                        if (name?.IsKind(SyntaxKind.IdentifierName) == true)
                        {
                            return((IdentifierNameSyntax)name);
                        }
                    }
                }
            }

            return(null);
        }
Exemple #3
0
        private static bool AddSimpleName(SimpleNameSyntax simpleName, List <string> parts)
        {
            if (!simpleName.IsKind(SyntaxKind.IdentifierName))
            {
                return(false);
            }

            parts.Add(simpleName.Identifier.ValueText);
            return(true);
        }
            public override void VisitArgument(ArgumentSyntax node)
            {
                CancellationToken.ThrowIfCancellationRequested();

                if (node.RefOrOutKeyword.IsKind(SyntaxKind.RefKeyword, SyntaxKind.OutKeyword))
                {
                    ExpressionSyntax expression = node.Expression?.WalkDownParentheses();

                    switch (expression?.Kind())
                    {
                    case SyntaxKind.IdentifierName:
                    {
                        if (IsBackingFieldReference((IdentifierNameSyntax)expression))
                        {
                            Success = false;
                        }

                        return;
                    }

                    case SyntaxKind.SimpleMemberAccessExpression:
                    {
                        var memberAccessExpression = (MemberAccessExpressionSyntax)expression;

                        if (memberAccessExpression.Expression.IsKind(SyntaxKind.ThisExpression))
                        {
                            SimpleNameSyntax name = memberAccessExpression.Name;

                            if (name.IsKind(SyntaxKind.IdentifierName))
                            {
                                if (IsBackingFieldReference((IdentifierNameSyntax)name))
                                {
                                    Success = false;
                                }

                                return;
                            }
                        }

                        break;
                    }
                    }
                }

                base.VisitArgument(node);
            }
        private static bool IsPropertyOfNullableOfT(ExpressionSyntax expression, string name, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (expression?.IsKind(SyntaxKind.SimpleMemberAccessExpression) == true)
            {
                var memberAccessExpression = (MemberAccessExpressionSyntax)expression;

                SimpleNameSyntax simpleName = memberAccessExpression.Name;

                if (simpleName?.IsKind(SyntaxKind.IdentifierName) == true)
                {
                    var identifierName = (IdentifierNameSyntax)simpleName;

                    return(string.Equals(identifierName.Identifier.ValueText, name, StringComparison.Ordinal) &&
                           SemanticUtilities.IsPropertyOfNullableOfT(expression, name, semanticModel, cancellationToken));
                }
            }

            return(false);
        }
Exemple #6
0
        private static TypeSyntax GetTypeArgument(SimpleNameSyntax name)
        {
            if (name.IsKind(SyntaxKind.GenericName))
            {
                var genericName = (GenericNameSyntax)name;

                TypeArgumentListSyntax typeArgumentList = genericName.TypeArgumentList;

                if (typeArgumentList?.IsMissing == false)
                {
                    SeparatedSyntaxList <TypeSyntax> typeArguments = typeArgumentList.Arguments;

                    if (typeArguments.Count == 1)
                    {
                        return(typeArguments.First());
                    }
                }
            }

            return(null);
        }