Custom null checking methods - Contract annotations not working

Hello!

I have implemented 'Contract Annotations' to perform custom 'null checks' - however my method still shows that a possible null reference may occur.

Am I doing anything wrong?

 

3 comments
Comment actions Permalink

Since you're using nullable reference types, you should probably use the built-in attributes instead of the JetBrains annotations.

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.notnullwhenattribute?view=net-6.0 
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis 

Specifically:

public static bool IsSmartNotNullOrEmpty([NotNullWhen(false)] this string? value)
1
Comment actions Permalink

Thank you! I will take a look at this. I was not aware of the ''[NotNullWhen(bool)]' attribute.

 

I will take a look at this and get back to you. Thank you!

0
Comment actions Permalink

Richard Deeming, thank you so much for your help! :)

0

Please sign in to leave a comment.