The C# plugin within Sonar flags methods where the cyclomatic complexity is greater than 10 (CSharpsquid:S1541 - Methods should not be too complex). This is great for 'real' code, but my team finds it annoying when a method containing just a simple 'switch' statement with 5 cases (used to translate one enum type into another enum type) is flagged as being too complex.
Is it possible to suppress the flag/rule on individual methods within the code-base? If so, how?
You cannot do this automatically.
Maybe instead of suppressing the rule you can use IMap. You can create a simple class which can translate enums:
public class Enum1ToEnum2Translator {
private static IMap<Enum1, Enum2> MAP = new Map<Enum1, Enum2>();
static {
MAP.add(Enum1.VAL1, Enum2.VAL1);
MAP.add(Enum1.VAL2, Enum2.VAL2);
MAP.add(Enum1.VAL3, Enum3.VAL3);
}
public Enum2 translate(Enum1 enum) {
return MAP.get(enum1);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With