-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: "CA2260: Implement Generic Math Interfaces Correctly" | ||
description: "Generic math interfaces require the derived type itself to be used for the self recurring type parameter" | ||
ms.date: 10/06/2022 | ||
ms.topic: reference | ||
f1_keywords: | ||
- CA2260 | ||
- ImplementGenericMathInterfacesCorrectly | ||
helpviewer_keywords: | ||
- ImplementGenericMathInterfacesCorrectly | ||
- CA2260 | ||
author: buyaa-n | ||
--- | ||
# CA2260: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported | ||
|
||
| | Value | | ||
| ----------------------------------- | ------------------------------------ | | ||
| **Rule ID** | CA2260 | | ||
| **Category** | [Usage](usage-warnings.md) | | ||
| **Fix is breaking or non-breaking** | Non-breaking | | ||
|
||
## Cause | ||
|
||
When not passing the type itself as a type parameter when implementing a generic math interface that requires self recurring type parameter. | ||
|
||
## Rule description | ||
|
||
Some generic math interfaces introduce static abstract members, the only way to access those static members is through a generic constraint, the generic constraints implements Curiously Recurring Template Pattern (CRTP), therefore require the derived type itself to be used for the self recurring type parameter. If a type implements such interface without passing required type parameter and CA2260 is ignored the code would compile successfully but the static abstract will not me accessible therefore the type will not be usable, compiler would warn with CS0315 on such usage. | ||
|
||
|
||
## How to fix violations | ||
|
||
Pass correct type parameter for self recurring type parameter (TSelf) when implementing those interfaces. | ||
|
||
### Example | ||
|
||
**Violation**: | ||
|
||
```csharp | ||
using System; | ||
|
||
// Warns: The 'IParsable<TSelf>' requires the 'TSelf' type parameter to be filled with the derived type 'MyDate' | ||
public readonly struct MyDate : IParsable<DateOnly> | ||
{ ... } | ||
``` | ||
|
||
**Fix**: | ||
|
||
If your array's elements are larger than one byte in size, you can multiply the length of the array by the element size to get the number of bytes. | ||
|
||
```csharp | ||
using System; | ||
|
||
// No warning | ||
public readonly struct MyDate : IParsable<MyDate> | ||
{ ... } | ||
``` | ||
|
||
## When to suppress errors | ||
|
||
Do not suppress a warning from this rule. | ||
|
||
## See also | ||
|
||
- [Usage warnings](usage-warnings.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters