| Property | Value |
|---|---|
| Package | Philips.CodeAnalysis.MaintainabilityAnalyzers |
| Diagnostic ID | PH2109 |
| Category | Maintainability |
| Analyzer | AlignOperatorCountAnalyzer |
| CodeFix | No |
| Severity | Error |
| Enabled By Default | Yes |
Users expect operators to be symmetrical, meaning that when overriding the shift right (>>) and shift left(<<) operator this needs to be done in pairs. For some operators the pairing rule is mandated by microsoft. This diagnostics extends the pairing to the shift reight and left operators.
Override the >> and << operators in pairs, with the same arguments.
Code that triggers a diagnostic:
class BadExample
{
public static BadExample operator >>(BadExample example1, int amount)
{
// Implementation
}
}And the replacement code:
class GoodExample
{
public static GoodExample operator >>(GoodExample example1, int amount)
{
// Implementation
}
public static GoodExample operator <<(GoodExample example1, int amount)
{
// Implementation
}
}This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.