Exemplo n.º 1
0
        protected override void InitializeWorker(ViewFeaturesAnalyzerContext analyzerContext)
        {
            analyzerContext.Context.RegisterOperationAction(context =>
            {
                var method = ((IInvocationOperation)context.Operation).TargetMethod;
                if (!analyzerContext.IsHtmlHelperExtensionMethod(method))
                {
                    return;
                }

                if (string.Equals(SymbolNames.PartialMethod, method.Name, StringComparison.Ordinal))
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 SupportedDiagnostic,
                                                 context.Operation.Syntax.GetLocation(),
                                                 new[] { SymbolNames.PartialMethod }));
                }
                else if (string.Equals(SymbolNames.RenderPartialMethod, method.Name, StringComparison.Ordinal))
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 SupportedDiagnostic,
                                                 context.Operation.Syntax.GetLocation(),
                                                 new[] { SymbolNames.RenderPartialMethod }));
                }
            }, OperationKind.Invocation);
        }
Exemplo n.º 2
0
        protected override void InitializeWorker(ViewFeaturesAnalyzerContext analyzerContext)
        {
            analyzerContext.Context.RegisterSyntaxNodeAction(context =>
            {
                var invocationExpression = (InvocationExpressionSyntax)context.Node;
                var symbol = context.SemanticModel.GetSymbolInfo(invocationExpression, context.CancellationToken).Symbol;
                if (symbol == null || symbol.Kind != SymbolKind.Method)
                {
                    return;
                }

                var method = (IMethodSymbol)symbol;
                if (!analyzerContext.IsHtmlHelperExtensionMethod(method))
                {
                    return;
                }

                if (string.Equals(SymbolNames.PartialMethod, method.Name, StringComparison.Ordinal))
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 SupportedDiagnostic,
                                                 invocationExpression.GetLocation(),
                                                 new[] { SymbolNames.PartialMethod }));
                }
                else if (string.Equals(SymbolNames.RenderPartialMethod, method.Name, StringComparison.Ordinal))
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 SupportedDiagnostic,
                                                 invocationExpression.GetLocation(),
                                                 new[] { SymbolNames.RenderPartialMethod }));
                }
            }, SyntaxKind.InvocationExpression);
        }
        public sealed override void Initialize(AnalysisContext context)
        {
            context.RegisterCompilationStartAction(compilationContext =>
            {
                var analyzerContext = new ViewFeaturesAnalyzerContext(compilationContext);

                // Only do work if we can locate IHtmlHelper.
                if (analyzerContext.HtmlHelperType == null)
                {
                    return;
                }

                InitializeWorker(analyzerContext);
            });
        }
Exemplo n.º 4
0
        public sealed override void Initialize(AnalysisContext context)
        {
            context.EnableConcurrentExecution();
            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
            context.RegisterCompilationStartAction(compilationContext =>
            {
                var analyzerContext = new ViewFeaturesAnalyzerContext(compilationContext);

                // Only do work if we can locate IHtmlHelper.
                if (analyzerContext.HtmlHelperType == null)
                {
                    return;
                }

                InitializeWorker(analyzerContext);
            });
        }
Exemplo n.º 5
0
 protected abstract void InitializeWorker(ViewFeaturesAnalyzerContext analyzerContext);