Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Implement alternative method 'xxx' for the operator 'yy'.
-
Highlighting:
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Covered Languages:C#
-
Irrelevant for Languages:ABAP, C, C++, Cobol, CSS, Flex, HTML, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Scope:Main Sources
-
FxCop:OperatorOverloadsHaveNamedAlternates, CA2225
Description
Operator overloading is convenient but unfortunately not portable across languages. To be able to access the same functionality from another language you need to provide an alternate named method following the convention:
Operator | Method Name |
---|---|
+ (binary) | Add |
& | BitwiseAnd |
| | BitwiseOr |
/ | Divide |
== | Equals |
^ | Xor |
> | Compare |
>= | Compare |
!= | Equals |
< | Compare |
<= | Compare |
! | LogicalNot |
% | Mod |
* (binary) | Multiply |
~ | OnesComplement |
- (binary) | Subtract |
- (unary) | Negate |
+ (unary) | Plus |
This rule raises an issue when there is an operator overload without the expected named alternative method.
Exceptions
This rule does not raise an issue when the class implementing the comparison operators >, <, >= and <= contains a method named CompareTo.
Attachments
Issue Links
- links to