Skip to content

Commit 4a58f94

Browse files
committed
Fix lint errors
1 parent 581a85f commit 4a58f94

File tree

1 file changed

+15
-14
lines changed
  • docs/fundamentals/code-analysis/quality-rules

1 file changed

+15
-14
lines changed

docs/fundamentals/code-analysis/quality-rules/ca2020.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ With the [numeric IntPtr feature](https://github.com/dotnet/csharplang/blob/main
4747
Investigate the code to determine if the expression flagged could cause a behavioral change, and choose appropriate way to fix the diagnostic
4848

4949
Fix options:
50-
- If the expression would not cause a behavioral change:
51-
- If the `IntPtr/UIntPtr` type used as native int/uint purpose change the type to `nint/nuint`.
52-
- If the `IntPtr/UIntPtr` type used as native pointer change the type to corresponding native pointer type
53-
- If you cannot change the type of the variable last resort will be suppress the warning
54-
- If the expression could cause a behavioral change wrap it with corresponding `checked`/`unchecked` statement to preserve the .NET 6.0 behavior.
50+
51+
- If the expression would not cause a behavioral change:
52+
- If the `IntPtr/UIntPtr` type used as native int/uint purpose change the type to `nint/nuint`.
53+
- If the `IntPtr/UIntPtr` type used as native pointer change the type to corresponding native pointer type
54+
- If you cannot change the type of the variable last resort will be suppress the warning
55+
- If the expression could cause a behavioral change wrap it with corresponding `checked`/`unchecked` statement to preserve the .NET 6.0 behavior.
5556

5657
### Example
5758

@@ -81,15 +82,15 @@ public unsafe class IntPtrTest
8182
intPtrVariable = (IntPtr)longVariable; // Starting with .NET 7 the explicit conversion '(IntPtr)Int64' will not throw when overflowing in an unchecked context. Wrap the expression with a 'checked' statement to restore the .NET 6 behavior.
8283
8384
int a = (int)intPtrVariable; // Starting with .NET 7 the explicit conversion '(Int32)IntPtr' will not throw when overflowing in an unchecked context. Wrap the expression with a 'checked' statement to restore the .NET 6 behavior.
84-
}
85+
}
8586
}
8687
```
8788

8889
**Fix**:
8990

90-
- If the expression would not cause a behavioral change:
91-
- If the IntPtr/UIntPtr type used as native int/uint purpose change the type to nint/nuint.
92-
91+
- If the expression would not cause a behavioral change:
92+
- If the IntPtr/UIntPtr type used as native int/uint purpose change the type to nint/nuint.
93+
9394
```csharp
9495
using System;
9596

@@ -114,11 +115,11 @@ public unsafe class IntPtrTest
114115
intPtrVariable = (nint)longVariable;
115116

116117
int a = (int)intPtrVariable;
117-
}
118+
}
118119
}
119-
```
120+
```
120121

121-
- If the expression could cause a behavioral change wrap it with corresponding `checked`/`unchecked` statement to preserve the old .NET 6.0 behavior.
122+
- If the expression could cause a behavioral change wrap it with corresponding `checked`/`unchecked` statement to preserve the old .NET 6.0 behavior.
122123

123124
```csharp
124125
using System;
@@ -144,9 +145,9 @@ public unsafe class IntPtrTest
144145
intPtrVariable = checked((IntPtr)longVariable); // wrap with checked
145146
146147
int a = checked((int)intPtrVariable); //
147-
}
148+
}
148149
}
149-
```
150+
```
150151

151152
## When to suppress warnings
152153

0 commit comments

Comments
 (0)