Prevent null forgiving operator usage

Viewed 140

As part of the work we do maintaining a project we typically end up discussing the null forgiving operator ! in PR reviews and have been trying to explore ways to prevent it's use altogether.

I am ideally trying to find a way to prevent it's usage through .editorconfig and forcing it to be an error however I have struggled to find any clear options. Is this possible?

If it isn't are there any known other ways of enforcing this desired behaviour?

1 Answers

I had started to write my own Roslyn Analyzer as suggested in comments until a friend pointed me at this repository which has already provided it:

https://github.com/tom-englert/Nullable.Extended

There is an extension or a NuGet Package option which looks exactly like we need.

Related