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?

4 comments
Comment actions Permalink

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 treating string! as a string that can never be null, in the same way that int? is an integer that can be null. In fact, you can also type string? 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. 

0
Comment actions Permalink

Thanks this helps

0
Comment actions Permalink

Thank you, that is helpful. For some reason, rider still replace ? with [CanBeNull] even on C# 8 projects

0
Comment actions Permalink
Hi Anno! Could you please check that settings described above are disabled? Please, attach your settings to the issue. What version of Rider do you use?
0

Please sign in to leave a comment.