Can I make VS code warn me of unnecessary null-forgiving operator usages?

Viewed 36

If I use a nullable value in a non-nullable context, VS code warns me with [CS8603] Possible null reference return.

Example: private object Foo(Func<object?> foo) { return foo(); } (VS code underlines foo())

It can be resolved e.g. by adding the null-forgiving operator (to foo() in that example).


Is there a way to make VS code warn in the inverse case, i.e. if I use a null-forgiving operator in a non-nullable context?

Example: private object Foo(Func<object> foo) { return foo()!; } (VS code should underline foo()!)

0 Answers
Related