question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please add [CanBeNull] attribute to some methods

See original GitHub issue

For example this method:

    [Pure]
    public static TValue GetValueOrDefault<TKey, TValue>([NotNull] this Dictionary<TKey, TValue> dictionary, TKey key)
    {
      return DictionaryExtensions.GetValueOrDefault<TKey, TValue>(dictionary, key, default (TValue));
    }

should have [CanBeNull] attribute applied, because it can return null when TValue is a class. Otherwise ReSharper does not help catch possible null reference exception.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ig-sinicyncommented, Jun 22, 2017

@MozgC I’ve marked only overloads that have no selector or explicit default value arg. If this is not what you want - let me know:)

1reaction
ig-sinicyncommented, Jun 22, 2017

@Lexey, OP is talking about marking the return value with [CanBeNull]. it looks reasonable for me.

@MozgC, will do. BTW doing a PR would work too:)

Read more comments on GitHub >

github_iconTop Results From Across the Web

C#: How to Implement and use a NotNull and CanBeNull ...
I want to let programmers and myself know that a method does not want null and if you do send null to it...
Read more >
Code annotation attributes | ReSharper Documentation
Indicates that the value of the marked element could be null sometimes, so checking for null is required before its usage. Example. [CanBeNull] ......
Read more >
Do you use attributes like CanBeNull and NotNull for every ...
I would like to know that you use these attributes and how much are they ... and NotNull for every parameter objects and...
Read more >
Rider always convert '?' into [CanBeNull]
Say i write this method: public IResult DoAction(IPlayer player, ... that IActor can be null, our convention is to basically add '?'
Read more >
Migrate from Jetbrains.Annotations [NotNull] / [CanBeNull] to ...
A screenshot demonstrating usage of the [CanBeNull] attribute in C#. Using the [NotNull] attribute helps notice a mistake. Here, null is not a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found