protected void VisitAttributeArgument(SyntaxNodeAnalysisContext ctx, SyntaxNodeHelper nodeHelper) { if (!nodeHelper.IsAttributeArgument(ctx.Node)) { return; } var name = nodeHelper.GetAttributeArgumentNode(ctx.Node); if (name == null) { return; } if (!name.ToString().EndsWith("TypeNameHandling")) { return; } var symbols = ctx.SemanticModel.GetSymbolInfo(name).Symbol; if (symbols == null) { return; } if (symbols.ContainingSymbol.ToString() != "Newtonsoft.Json.JsonPropertyAttribute") { return; } ReportIfTypeNameHandlingIsNotNone(ctx, nodeHelper.GetAttributeArgumentExpressionNode(ctx.Node)); }
protected void CheckValidateInput(SyntaxNodeAnalysisContext ctx, SyntaxNodeHelper nodeHelper) { foreach (var attribute in nodeHelper.GetDeclarationAttributeNodes(ctx.Node)) { var hasArgumentFalse = false; SyntaxNode expression = null; foreach (var arg in nodeHelper.GetAttributeArgumentNodes(attribute)) { expression = nodeHelper.GetAttributeArgumentExpressionNode(arg); var expressionValue = ctx.SemanticModel.GetConstantValue(expression); if (!expressionValue.HasValue) { continue; } if (expressionValue.Value is bool value && value == false) { hasArgumentFalse = true; break; } } if (!hasArgumentFalse) { continue; } var attributeSymbols = ctx.SemanticModel.GetSymbolInfo(attribute).Symbol; if (attributeSymbols == null) { continue; } var containingSymbol = attributeSymbols.ContainingSymbol.ToString(); if (containingSymbol != "System.Web.Mvc.ValidateInputAttribute") { continue; } ctx.ReportDiagnostic(Diagnostic.Create(Rule, expression.GetLocation())); return; } }