private void AnalyzeSwitchStatement(SyntaxNodeAnalysisContext context) { var switchStatement = (SwitchStatementSyntax)context.Node; var switchAnalyzer = new SwitchAnalyzer(switchStatement, context.SemanticModel); if (!switchAnalyzer.SwitchOverEnum) { return; } if (!DefaultSectionThrows(switchStatement, context.SemanticModel)) { return; } var enumValues = switchAnalyzer.SortedEnumFIeldsAndValues; var enums = switchAnalyzer.SortedEnumFIeldsAndValues.ToDictionarySafe(e => e.Item1, e => e.Item2); var cases = switchAnalyzer.Cases; var uniqueCases = new HashSet <long>(cases.Select(c => c.Item2)); var nonCoveredValues = enumValues .ToDictionarySafe(e => e.Item2, e => e.Item1) .Where(kvp => !uniqueCases.Contains(kvp.Key)) .ToList(); if (nonCoveredValues.Count != 0) { string message = string.Join(",", nonCoveredValues.Select(kvp => $"'{kvp.Value.Name}'")); context.ReportDiagnostic( Diagnostic.Create(Rule, switchStatement.SwitchKeyword.GetLocation(), message)); } }
private void AnalyzeSwitchStatement(SyntaxNodeAnalysisContext context) { var switchStatement = (SwitchStatementSyntax)context.Node; var switchAnalyzer = new SwitchAnalyzer(switchStatement, context.SemanticModel); if (!switchAnalyzer.SwitchOverEnum) { return; } if (!DefaultSectionThrows(switchStatement, context.SemanticModel)) { return; } var enumValues = switchAnalyzer.SortedEnumFIeldsAndValues; var enums = switchAnalyzer.SortedEnumFIeldsAndValues.ToDictionarySafe(e => e.Item1, e => e.Item2); var cases = switchAnalyzer.Cases; var uniqueCases = new HashSet<long>(cases.Select(c => c.Item2)); var nonCoveredValues = enumValues .ToDictionarySafe(e => e.Item2, e => e.Item1) .Where(kvp => !uniqueCases.Contains(kvp.Key)) .ToList(); if (nonCoveredValues.Count != 0) { string message = string.Join(",", nonCoveredValues.Select(kvp => $"'{kvp.Value.Name}'")); context.ReportDiagnostic( Diagnostic.Create(Rule, switchStatement.SwitchKeyword.GetLocation(), message)); } }