A value is tested with is and then cast to the same type
What it finds
if (shape is Circle) { var c = (Circle)shape; ... } checks the type twice. A pattern, if (shape is Circle c), tests and converts at once.
From the rule's source, type_check_then_cast.rs.
class Shapes{ double Radius(object shape) { if (shape is Circle) { return ((Circle)shape).Radius;tx0 reports: the value was already tested for this type } if (shape is Circle c) { return c.Radius; } return 0; }} class Circle{ public double Radius;} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:type-check-then-cast" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:type-check-then-cast] reason="..."tx0 explain tx0/csharp:type-check-then-cast shows the same in the terminal. Found a false positive? Report it.