protected void VisitAttributeArgument(SyntaxNodeAnalysisContext ctx, SyntaxNodeHelper nodeHelper) { var name = nodeHelper.GetNameNode(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.GetAttributeArgumentExpresionNode(ctx.Node)); }
private void CheckValidateInput(SyntaxNodeAnalysisContext ctx, SyntaxNodeHelper nodeHelper) { foreach (var attribute in nodeHelper.GetDeclarationAttributeNodes(ctx.Node)) { if (!nodeHelper.GetNameNode(attribute).ToString().Contains("ValidateInput")) { continue; } var hasArgumentFalse = false; SyntaxNode expression = null; foreach (var arg in nodeHelper.GetAttributeArgumentNodes(attribute)) { expression = nodeHelper.GetAttributeArgumentExpresionNode(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; } }