Adopt nullable reference types
See original GitHub issueThe 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:
- Created 2 years ago
- Comments:16 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 likeFirstOrDefault
.GetAttributeByPublicName
- I would expect it to throw an exception if it can’t find the attribute by that public nameFindAttributeByPublicName
- I would expect it to returnnull
if it can’t find the specified attributeTryGetAttributeByPublicName
- This is a common convention. It would returnfalse
if it can’t find the specific attribute. It would returntrue
if it can and pass the attribute through theout
parameter. However, if thepublicName
parameter isnull
orempty
, I would expect anArgumentNullException
orArgumentException
.