private bool TryFindEntityInterface(SyntaxNode identifierName, SyntaxNodeAnalysisContext context, out EntityInterface entityInterface)
        {
            var interfaceSymbol = context.SemanticModel.GetSymbolInfo(identifierName, context.CancellationToken).Symbol;

            if (interfaceSymbol != null)
            {
                var syntaxReference = interfaceSymbol.DeclaringSyntaxReferences.FirstOrDefault();
                if (syntaxReference != null)
                {
                    var declaration = syntaxReference.GetSyntax(context.CancellationToken);
                    if (declaration != null)
                    {
                        var interfaceKeyword = declaration.ChildTokens().Where(x => x.IsKind(SyntaxKind.InterfaceKeyword));
                        if (interfaceKeyword.Any())
                        {
                            var interfaceType = context.SemanticModel.GetTypeInfo(declaration).Type;

                            entityInterface = new EntityInterface {
                                name = identifierName.ToString(), InterfaceDeclaration = declaration, typeSymbol = interfaceType
                            };
                            return(true);
                        }
                    }
                }
            }

            entityInterface = null;
            return(false);
        }
        private bool TryFindEntityInterface(SyntaxNodeAnalysisContext context, SyntaxNode identifierName, out EntityInterface entityInterface)
        {
            if (SyntaxNodeUtils.TryGetDeclaredSyntaxNode(context.SemanticModel, identifierName, out SyntaxNode declaration))
            {
                if (IsInterface(declaration))
                {
                    entityInterface = new EntityInterface {
                        Name = identifierName.ToString(), InterfaceDeclaration = declaration
                    };
                    return(true);
                }
            }

            entityInterface = null;
            return(false);
        }
        public static void ReportProblems(CompilationAnalysisContext context, EntityInterface entityInterface)
        {
            var childNodes = entityInterface.InterfaceDeclaration.ChildNodes();

            foreach (var node in childNodes)
            {
                if (SyntaxNodeUtils.TryGetMethodReturnTypeNode(node, out SyntaxNode returnTypeNode))
                {
                    var returnType = returnTypeNode.ToString();
                    if (!returnType.Equals("void") && !returnType.StartsWith("Task"))
                    {
                        var diagnostic = Diagnostic.Create(Rule, node.GetLocation(), returnType);

                        context.ReportDiagnostic(diagnostic);
                    }
                }
            }
        }
예제 #4
0
        public void ReportProblems(CompilationAnalysisContext context, EntityInterface entityInterface)
        {
            var childNodes = entityInterface.InterfaceDeclaration.ChildNodes();

            foreach (var node in childNodes)
            {
                if (node.IsKind(SyntaxKind.MethodDeclaration))
                {
                    var returnTypeNode = node.ChildNodes().Where(x => x.IsKind(SyntaxKind.PredefinedType) || x.IsKind(SyntaxKind.IdentifierName) || x.IsKind(SyntaxKind.GenericName));
                    if (returnTypeNode.Any())
                    {
                        var returnType = returnTypeNode.First().ToString();
                        if (!returnType.Equals("void") && !returnType.StartsWith("Task"))
                        {
                            var diagnostic = Diagnostic.Create(Rule, node.GetLocation(), returnType);

                            context.ReportDiagnostic(diagnostic);
                        }
                    }
                }
            }
        }
예제 #5
0
        public static void ReportProblems(CompilationAnalysisContext context, EntityInterface entityInterface)
        {
            var interfaceDeclaration = entityInterface.InterfaceDeclaration;
            var interfaceChildNodes  = interfaceDeclaration.ChildNodes();

            if (!interfaceChildNodes.Any())
            {
                var diagnostic = Diagnostic.Create(NoMethodsRule, interfaceDeclaration.GetLocation(), interfaceDeclaration);

                context.ReportDiagnostic(diagnostic);
                return;
            }

            foreach (var node in interfaceChildNodes)
            {
                if (!node.IsKind(SyntaxKind.MethodDeclaration))
                {
                    var diagnostic = Diagnostic.Create(NotAMethodRule, node.GetLocation(), node);

                    context.ReportDiagnostic(diagnostic);
                }
            }
        }
예제 #6
0
        public static void ReportProblems(CompilationAnalysisContext context, EntityInterface entityInterface)
        {
            var interfaceChildNodes = entityInterface.InterfaceDeclaration.ChildNodes();

            foreach (var node in interfaceChildNodes)
            {
                if (node.IsKind(SyntaxKind.MethodDeclaration))
                {
                    var parameterList = node.ChildNodes().Where(x => x.IsKind(SyntaxKind.ParameterList));
                    if (!parameterList.Any())
                    {
                        return;
                    }
                    var parameters = parameterList.First().ChildNodes().Where(x => x.IsKind(SyntaxKind.Parameter));
                    if (parameters.Count() > 1)
                    {
                        var diagnostic = Diagnostic.Create(Rule, node.GetLocation(), node);

                        context.ReportDiagnostic(diagnostic);
                    }
                }
            }
        }
예제 #7
0
        private bool TryFindEntityInterface(SyntaxNodeAnalysisContext context, SyntaxNode identifierName, out EntityInterface entityInterface)
        {
            if (SyntaxNodeUtils.TryGetISymbol(context.SemanticModel, identifierName, out ISymbol interfaceSymbol))
            {
                var syntaxReference = interfaceSymbol.DeclaringSyntaxReferences.FirstOrDefault();
                if (syntaxReference != null)
                {
                    var declaration = syntaxReference.GetSyntax(context.CancellationToken);
                    if (declaration != null)
                    {
                        if (IsInterface(declaration))
                        {
                            entityInterface = new EntityInterface {
                                Name = identifierName.ToString(), InterfaceDeclaration = declaration
                            };
                            return(true);
                        }
                    }
                }
            }

            entityInterface = null;
            return(false);
        }