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.

Adopt nullable reference types

See original GitHub issue

The plan is to enable nullable reference types and review the nullability of all code (ie choose between nullable vs non-nullable references). A prerequisite for this is .NET 5 because of its improved unconstrained generics support.

In the process, we’ll likely want to make breaking changes to clarify the contract. For example IResourceContextProvider.GetResourceContext() today returns null when not found. Due to this loose contract, all callers are required to null-check or possibly face a NullReferenceException. So instead we’d like to offer ResourceContext GetResourceContext() (throws when not found) and ResourceContext? TryGetResourceContext (returns null when not found).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bart-degreedcommented, Oct 12, 2021

Thanks for sharing your insights @dennisdoomen, greatly appreciated. As usual, there is no single right solution, so I’m going to choose on a case-by-case basis.

For our resource graph lookups, I believe Find* is the most appropriate fit.

1reaction
dennisdoomencommented, Oct 11, 2021

I don’t know enough about your library to provide any specific advice, but I can provide generic advice about what I would expect:

  • GetAttributeByPublicNameOrDefault - Makes total sense to me and aligns with LINQ’s API like FirstOrDefault.
  • GetAttributeByPublicName - I would expect it to throw an exception if it can’t find the attribute by that public name
  • FindAttributeByPublicName - I would expect it to return null if it can’t find the specified attribute
  • TryGetAttributeByPublicName - This is a common convention. It would return false if it can’t find the specific attribute. It would return true if it can and pass the attribute through the out parameter. However, if the publicName parameter is null or empty, I would expect an ArgumentNullException or ArgumentException.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Update your codebase to use nullable reference types
Nullable reference types enable you to declare if variables of a reference type should or shouldn't be assigned a null value.
Read more >
What's New for C# Nullable Reference Types in ReSharper ...
Nullable reference types are easy to use in new solutions, but adopting them in large existing codebases is a tough task.
Read more >
Overthinking CSV With Cesil: Adopting Nullable Reference ...
In C# 8+, if nullable reference types are enabled, the compiler will raise a warning if it cannot prove that /* something */...
Read more >
C# 8.0 nullable references: getting started in an existing ...
Fortunately, nullable types are not like this: it is possible to adopt them selectively, and gradually. You can go one file at a...
Read more >
Start dealing with Nullable Reference Types! - Xebia
Since C# 8, developers can opt-in to use Nullable Reference Types (NRTs). With NRTs, developers get a set of 'tools' to avoid the...
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