Skip to content

Commit 5336441

Browse files
authored
Merge pull request #5516 from gewarren/ca2225
Update CA2225 description and table
2 parents 6fefea2 + e5eb6dd commit 5336441

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

docs/code-quality/ca2225-operator-overloads-have-named-alternates.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ ms.assetid: af8f7ab1-63ad-4861-afb9-b7a7a2be15e1
1212
author: gewarren
1313
ms.author: gewarren
1414
manager: jillfra
15-
ms.workload:
16-
- "multiple"
15+
dev_langs:
16+
- CSharp
1717
---
1818
# CA2225: Operator overloads have named alternates
1919

@@ -32,12 +32,16 @@ By default, this rule only looks at externally visible types, but this is [confi
3232

3333
## Rule description
3434

35-
Operator overloading allows the use of symbols to represent computations for a type. For example, a type that overloads the plus symbol (+) for addition would typically have an alternative member named 'Add'. The named alternative member provides access to the same functionality as the operator, and is provided for developers who program in languages that do not support overloaded operators.
35+
Operator overloading allows the use of symbols to represent computations for a type. For example, a type that overloads the plus symbol `+` for addition would typically have an alternative member named `Add`. The named alternative member provides access to the same functionality as the operator. It's provided for developers who program in languages that do not support overloaded operators.
3636

37-
This rule examines the operators listed in the following table.
37+
This rule examines:
3838

39-
|C#|Visual Basic|C++|Alternate name|
40-
|---------|------------------|-----------|--------------------|
39+
- Implicit and explicit cast operators in a type by checking for methods named `To<typename>` and `From<typename>`.
40+
41+
- The operators listed in the following table:
42+
43+
|C#|Visual Basic|C++|Alternate method name|
44+
|-|-|-|-|
4145
|+ (binary)|+|+ (binary)|Add|
4246
|+=|+=|+=|Add|
4347
|&|And|&|BitwiseAnd|
@@ -50,14 +54,14 @@ This rule examines the operators listed in the following table.
5054
|==|=|==|Equals|
5155
|^|Xor|^|Xor|
5256
|^=|Xor=|^=|Xor|
53-
|>|>|>|Compare|
54-
|>=|>=|>=|Compare|
57+
|>|>|>|CompareTo or Compare|
58+
|>=|>=|>=|CompareTo or Compare|
5559
|++|N/A|++|Increment|
56-
|<>|!=|Equals|
60+
|!=|<>|!=|Equals|
5761
|<<|<<|<<|LeftShift|
5862
|<<=|<<=|<<=|LeftShift|
59-
|<|<|<|Compare|
60-
|<=|<=|\<=|Compare|
63+
|<|<|<|CompareTo or Compare|
64+
|<=|<=|\<=|CompareTo or Compare|
6165
|&&|N/A|&&|LogicalAnd|
6266
|&#124;&#124;|N/A|&#124;&#124;|LogicalOr|
6367
|!|N/A|!|LogicalNot|
@@ -75,19 +79,18 @@ This rule examines the operators listed in the following table.
7579
|+ (unary)|N/A|+|Plus|
7680
|false|IsFalse|False|IsTrue (Property)|
7781

78-
N/A == Cannot be overloaded in the selected language.
79-
80-
The rule also checks implicit and explicit cast operators in a type (`SomeType`) by checking for methods named `ToSomeType` and `FromSomeType`.
82+
*N/A means the operator cannot be overloaded in the selected language.
8183

82-
In C#, when a binary operator is overloaded, the corresponding assignment operator, if any, is also implicitly overloaded.
84+
> [!NOTE]
85+
> In C#, when a binary operator is overloaded, the corresponding assignment operator, if any, is also implicitly overloaded.
8386
8487
## How to fix violations
8588

86-
To fix a violation of this rule, implement the alternative method for the operator; name it using the recommended alternative name.
89+
To fix a violation of this rule, implement the alternative method for the operator. Name it using the recommended alternative name.
8790

8891
## When to suppress warnings
8992

90-
Do not suppress a warning from this rule if you are implementing a shared library. Applications can ignore a warning from this rule.
93+
Do not suppress a warning from this rule if you're implementing a shared library. Applications can ignore a warning from this rule.
9194

9295
## Configurability
9396

0 commit comments

Comments
 (0)