Make sure to read this post before raising a thread here:
Then tell us:
-
What language is this for?
C# -
Which rule?
S3172 Delegates should not be subtracted -
Why do you believe it’s a false-positive/false-negative?
The exact same code but written as a traditional switch statement does not trigger this analyzer -
Are you using
- SonarLint - 7.4.0.80741 / Visual Studio 17.8.2
-
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
public static void UnSubscribeActions<T>(this IEnumerable<IDbSaveActions> dbSaveActions, Action<T> action, /*enum to switch on*/RequiredActions requiredAction) where T : DbContext
{
foreach (var saveAction in dbSaveActions.Where(x => x.RequiredActions.HasFlag(requiredAction)))
{
action -= requiredAction switch
{
RequiredActions.PreSaveAction => saveAction.Pre,
RequiredActions.PostSaveAction => saveAction.Post,
_ => throw new NotImplementedException(NotImplemented(requiredAction)),
};
}
}