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); }
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); }