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
    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.º 3
0
 protected abstract void InitializeWorker(ViewFeaturesAnalyzerContext analyzerContext);