Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.75 KB

File metadata and controls

54 lines (41 loc) · 1.75 KB

PH2109: Align number of >> and << operators

Property Value
Package Philips.CodeAnalysis.MaintainabilityAnalyzers
Diagnostic ID PH2109
Category Maintainability
Analyzer AlignOperatorCountAnalyzer
CodeFix No
Severity Error
Enabled By Default Yes

Introduction

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.

How to solve

Override the >> and << operators in pairs, with the same arguments.

Example

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
    }
}

Configuration

This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.