Rider always convert '?' into [CanBeNull]
Answered
How do I prevent this auto conversion?
Say i write this method:
public IResult DoAction(IPlayer player, IActor actor) {
...
}
When I try to indicate that IActor can be null, our convention is to basically add '?'
public IResult DoAction(IPlayer player, IActor? actor) {
...
}
But currently rider always coverts it into
public IResult DoAction(IPlayer player, [CanBeNull] IActor actor) {
...
}
How do I prevent it from happening?
Please sign in to leave a comment.
Hello, Zhen Liu!
Why do you need to prevent this?
As my colleague says:
The
! and ?are a typing assist helper. The idea is to make it easy to annotate type usages with[NotNull], by treatingstring!as a string that can never be null, in the same way thatint?is an integer that can be null. In fact, you can also typestring?to annotate with the[CanBeNull]attribute. These attributes improve Rider's null data flow analysis, and can be used to warn you to check for nulls, or that a null check is redundant.Anyway, you can disable this typing assist as shown on the picture.
Thanks this helps
Thank you, that is helpful. For some reason, rider still replace ? with [CanBeNull] even on C# 8 projects
Very easy - what if my colleagues don't use Rider? The problem is that Rider not only substitutes this in the editor, but it changes a code.
Hi Virtualmaestro!
Thank you for the details, that is a good point. Could you please clarify, do you have the described issue if you disable typing assist in the settings?
Thanks!
Hi Alexandra,
No, I've disabled it and now Rider doesn't substitute
.
Thanks!