private static void Analyze(SyntaxNodeAnalysisContext context, SwitchExpressionSyntaxWrapper switchExpression)
        {
            var arms = switchExpression.Arms;

            if (arms.Count < 2)
            {
                return;
            }
            var firstArm = arms[0];

            if (switchExpression.HasDiscardPattern() &&
                arms.Skip(1).All(arm => SyntaxFactory.AreEquivalent(arm.Expression, firstArm.Expression)))
            {
                context.ReportDiagnostic(Diagnostic.Create(rule, switchExpression.SwitchKeyword.GetLocation(), StatementsMessage));
            }
        }
コード例 #2
0
 private static SwitchExpressionType EvaluateType(SwitchExpressionSyntaxWrapper switchExpression)
 {
     var numberOfArms = switchExpression.Arms.Count;
     if (numberOfArms > 2)
     {
         return SwitchExpressionType.ManyReturnValues;
     }
     var hasDiscardValue = switchExpression.HasDiscardPattern();
     if (numberOfArms == 2)
     {
         return hasDiscardValue ? SwitchExpressionType.TwoReturnValues : SwitchExpressionType.ManyReturnValues;
     }
     if (numberOfArms == 1)
     {
         return hasDiscardValue ? SwitchExpressionType.SingleReturnValue : SwitchExpressionType.TwoReturnValues;
     }
     return SwitchExpressionType.SingleReturnValue;
 }