public override DotnetStylePredefinedTypeForMemberAccessStyle Update(ModelNodeInformation <MemberAccessExpressionSyntax> information)
        {
            var(node, model) = information ?? throw new ArgumentNullException(nameof(information));

            if (!node.ContainsDiagnostics)
            {
                if (node.DescendantNodes().Any(_ => _.Kind() == SyntaxKind.PredefinedType))
                {
                    return(new DotnetStylePredefinedTypeForMemberAccessStyle(
                               this.Data.Update(true), this.Severity));
                }
                else
                {
                    if (node.DescendantNodes().FirstOrDefault(_ => _.Kind() == SyntaxKind.IdentifierName) is IdentifierNameSyntax identifierNode)
                    {
                        if (model.GetSymbolInfo(identifierNode).Symbol is ITypeSymbol identifierType &&
                            identifierType.SpecialType.IsPredefinedType())
                        {
                            return(new DotnetStylePredefinedTypeForMemberAccessStyle(
                                       this.Data.Update(false), this.Severity));
                        }
                    }
                }
            }

            return(new DotnetStylePredefinedTypeForMemberAccessStyle(this.Data, this.Severity));
        }
        public override CSharpStylePatternMatchingOverAsWithNullCheckStyle Update(ModelNodeInformation <SyntaxNode> information)
        {
            var(node, model) = information ?? throw new ArgumentNullException(nameof(information));

            if (!node.ContainsDiagnostics)
            {
                if (node is IsPatternExpressionSyntax && node.FindParent <IfStatementSyntax>() is { })
        public override DotnetStyleExplicitTupleNamesStyle Update(ModelNodeInformation <MemberAccessExpressionSyntax> information)
        {
            var(node, model) = information ?? throw new ArgumentNullException(nameof(information));

            if (!node.ContainsDiagnostics)
            {
                if (model.GetSymbolInfo(node).Symbol is IFieldSymbol field)
                {
                    var correspondingTupleField = field.CorrespondingTupleField;

                    if (correspondingTupleField is { })
Exemplo n.º 4
0
        public override DotnetStyleObjectInitializerStyle Update(ModelNodeInformation <ObjectCreationExpressionSyntax> information)
        {
            var(node, model) = information ?? throw new ArgumentNullException(nameof(information));

            if (!node.ContainsDiagnostics)
            {
                if (node.ChildNodes().Any(_ => _.IsKind(SyntaxKind.ObjectInitializerExpression)))
                {
                    return(new DotnetStyleObjectInitializerStyle(this.Data.Update(true), this.Severity));
                }
                else
                {
                    var assignment = node.FindParent <VariableDeclaratorSyntax>() ??
                                     node.FindParent <AssignmentExpressionSyntax>()?.ChildNodes()
                                     .FirstOrDefault(_ => _.IsKind(SyntaxKind.SimpleMemberAccessExpression));

                    if (assignment is { })
        public override DotnetStyleQualificationForMethodStyle Update(ModelNodeInformation <InvocationExpressionSyntax> information)
        {
            var(node, model) = information ?? throw new ArgumentNullException(nameof(information));

            if (!node.ContainsDiagnostics)
            {
                if (model.GetSymbolInfo(node).Symbol is IMethodSymbol methodSymbol)
                {
                    if (node.DescendantNodes().Any(_ => _.Kind() == SyntaxKind.ThisExpression))
                    {
                        return(new DotnetStyleQualificationForMethodStyle(this.Data.Update(true), this.Severity));
                    }
                    else
                    {
                        var classNode = node.FindParent <ClassDeclarationSyntax>();

                        if (!methodSymbol.IsStatic && classNode is { } &&
Exemplo n.º 6
0
        public override CSharpStylePatternLocalOverAnonymousFunctionStyle Update(ModelNodeInformation <SyntaxNode> information)
        {
            var(node, model) = information ?? throw new ArgumentNullException(nameof(information));

            if (!node.ContainsDiagnostics)
            {
                if (node is LocalFunctionStatementSyntax function)
                {
                    return(new CSharpStylePatternLocalOverAnonymousFunctionStyle(this.Data.Update(true), this.Severity));
                }
                else if (node is VariableDeclarationSyntax variable)
                {
                    ISymbol?variableSymbol = default;

                    if (node.ChildNodes().SingleOrDefault(_ => _ is GenericNameSyntax) is GenericNameSyntax genericVariable)
                    {
                        variableSymbol = model.GetSymbolInfo(genericVariable).Symbol;
                    }
                    else if (node.ChildNodes().SingleOrDefault(_ => _ is IdentifierNameSyntax) is IdentifierNameSyntax identifierVariable)
                    {
                        variableSymbol = model.GetSymbolInfo(identifierVariable).Symbol;
                    }

                    if (variableSymbol is INamedTypeSymbol namedVariableSymbol &&
                        namedVariableSymbol.TypeKind == TypeKind.Delegate)
                    {
                        var original = namedVariableSymbol.OriginalDefinition;

                        if ((original.Name.StartsWith("Action") || original.Name.StartsWith("Func")) &&
                            original.ContainingNamespace?.Name == "System")
                        {
                            return(new CSharpStylePatternLocalOverAnonymousFunctionStyle(
                                       this.Data.Update(false), this.Severity));
                        }
                    }
                }
            }

            return(new CSharpStylePatternLocalOverAnonymousFunctionStyle(this.Data, this.Severity));
        }