private void ReportIssue(ExpressionStatus status, Location location, string errorContext) { switch (status) { case ExpressionStatus.NotAssigned: context.ReportDiagnostic(MainAnalyzer.CreateNullAssignmentError(location, errorContext)); break; case ExpressionStatus.ReassignedAfterCondition: context.ReportDiagnostic(MainAnalyzer.CreateAssignmentAfterCondition(location, errorContext)); break; case ExpressionStatus.AssignedWithUnneededConstraint: context.ReportDiagnostic(MainAnalyzer.CreateUnneededConstraint(location, errorContext)); break; } }
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node) { base.VisitAssignmentExpression(node); var valueType = node.Right.GetTypeOfValue(context.SemanticModel); if (valueType == ValueType.NotNull) { return; } var target = node.Left.FindUnderlyingMember(); if (target == null) { return; } var symbol = context.SemanticModel.GetSymbolInfo(target).Symbol; if (!symbol.HasNotNullOrCheckNull()) { return; } switch (GetAssignmentStatus(node.Right, node, valueType)) { case ExpressionStatus.NotAssigned: context.ReportDiagnostic(MainAnalyzer.CreateNullAssignmentError(node.GetLocation(), symbol)); break; case ExpressionStatus.ReassignedAfterCondition: context.ReportDiagnostic(MainAnalyzer.CreateAssignmentAfterCondition(node.GetLocation(), node.ToString())); break; case ExpressionStatus.AssignedWithUnneededConstraint: context.ReportDiagnostic(MainAnalyzer.CreateUnneededConstraint(node.GetLocation(), node.ToString())); break; } }