public override void VisitRangeCaseClause(IRangeCaseClause operation) { LogString(nameof(IRangeCaseClause)); LogCaseClauseCommon(operation); Visit(operation.MinimumValue, "Min"); Visit(operation.MaximumValue, "Max"); }
public virtual void VisitRangeCaseClause(IRangeCaseClause operation) { DefaultVisit(operation); }
public virtual void VisitRangeCaseClause(IRangeCaseClause operation) { DefaultVisit(operation); }
public override void VisitRangeCaseClause(IRangeCaseClause operation) { Visit(operation.MinimumValue); Visit(operation.MaximumValue); }
public sealed override void Initialize(AnalysisContext context) { context.RegisterOperationAction( (operationContext) => { ISwitchStatement switchOperation = (ISwitchStatement)operationContext.Operation; long minCaseValue = long.MaxValue; long maxCaseValue = long.MinValue; long caseValueCount = 0; foreach (ICase switchCase in switchOperation.Cases) { foreach (ICaseClause clause in switchCase.Clauses) { switch (clause.CaseKind) { case CaseKind.SingleValue: { ISingleValueCaseClause singleValueClause = (ISingleValueCaseClause)clause; IExpression singleValueExpression = singleValueClause.Value; if (singleValueExpression.ConstantValue != null && singleValueExpression.ResultType.SpecialType == SpecialType.System_Int32) { int singleValue = (int)singleValueExpression.ConstantValue; caseValueCount += IncludeClause(singleValue, singleValue, ref minCaseValue, ref maxCaseValue); } else { return; } break; } case CaseKind.Range: { IRangeCaseClause rangeClause = (IRangeCaseClause)clause; IExpression rangeMinExpression = rangeClause.MinimumValue; IExpression rangeMaxExpression = rangeClause.MaximumValue; if (rangeMinExpression.ConstantValue != null && rangeMinExpression.ResultType.SpecialType == SpecialType.System_Int32 && rangeMaxExpression.ConstantValue != null && rangeMaxExpression.ResultType.SpecialType == SpecialType.System_Int32) { int rangeMinValue = (int)rangeMinExpression.ConstantValue; int rangeMaxValue = (int)rangeMaxExpression.ConstantValue; caseValueCount += IncludeClause(rangeMinValue, rangeMaxValue, ref minCaseValue, ref maxCaseValue); } else { return; } break; } case CaseKind.Relational: { IRelationalCaseClause relationalClause = (IRelationalCaseClause)clause; IExpression relationalValueExpression = relationalClause.Value; if (relationalValueExpression.ConstantValue != null && relationalValueExpression.ResultType.SpecialType == SpecialType.System_Int32) { int rangeMinValue = int.MaxValue; int rangeMaxValue = int.MinValue; int relationalValue = (int)relationalValueExpression.ConstantValue; switch (relationalClause.Relation) { case BinaryOperationKind.IntegerEquals: rangeMinValue = relationalValue; rangeMaxValue = relationalValue; break; case BinaryOperationKind.IntegerNotEquals: return; case BinaryOperationKind.IntegerLessThan: rangeMinValue = int.MinValue; rangeMaxValue = relationalValue - 1; break; case BinaryOperationKind.IntegerLessThanOrEqual: rangeMinValue = int.MinValue; rangeMaxValue = relationalValue; break; case BinaryOperationKind.IntegerGreaterThanOrEqual: rangeMinValue = relationalValue; rangeMaxValue = int.MaxValue; break; case BinaryOperationKind.IntegerGreaterThan: rangeMinValue = relationalValue + 1; rangeMaxValue = int.MaxValue; break; } caseValueCount += IncludeClause(rangeMinValue, rangeMaxValue, ref minCaseValue, ref maxCaseValue); } else { return; } break; } case CaseKind.Default: { break; } } } } long span = maxCaseValue - minCaseValue + 1; if (caseValueCount == 0 || span / caseValueCount > 100) { Report(operationContext, switchOperation.Value.Syntax, SparseSwitchDescriptor); } }, OperationKind.SwitchStatement); }
/// <inheritdoc /> public override IOperation VisitRangeCaseClause(IRangeCaseClause operation, object argument) { return(base.VisitRangeCaseClause(operation, argument)); }
public override IOperation VisitRangeCaseClause(IRangeCaseClause operation, object argument) { return(new RangeCaseClause(Visit(operation.MinimumValue), Visit(operation.MaximumValue), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }
/// <inheritdoc /> public override Expression VisitRangeCaseClause(IRangeCaseClause operation, LocalBinder argument) { throw Unexpected(operation, nameof(VisitSwitchStatement)); }