Skip to main content

RCS9001: Use pattern matching

Properties

PropertyValue
Default SeverityHidden
Minimum language version-

Examples

Example #1

diagnostic.cs
if (syntaxNode.IsKind(SyntaxKind.IdentifierName))
{
var identifierName = (IdentifierNameSyntax)syntaxNode;
}
fix.cs
if (syntaxNode is IdentifierNameSyntax identifierName)
{
}

Example #2

diagnostic.cs
if (!syntaxNode.IsKind(SyntaxKind.IdentifierName))
{
return;
}

var identifierName = (IdentifierNameSyntax)syntaxNode;
fix.cs
if (!(syntaxNode is IdentifierNameSyntax identifierName))
{
return;
}

Applies to