C# Is pattern expression

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);

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

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.