C# Is pattern expression

csharp

(Raphael Saldanha) #1

When is pattern is used

static bool Evaluate(object value)
    => value is string stringValue && string.IsNullOrWhiteSpace(stringValue);

Sonarqube detects it as code smell: “Change this condition so that it does not always evaluate to ‘false’”

But it works as expected when is pattern is not used

static bool Evaluate(object value)
    => value is string && string.IsNullOrWhiteSpace(value as string);

(Amaury Levé) #2

Hi @Raphael_Saldanha,

You are right! Some of our rules don’t yet handle properly all C# 7 features which explains why you have this FP.

Cheers,
Amaury