简体   繁体   中英

I am starting a new .Net Core project and I can't figure out how am I supposed to implement nullable reference types for nuget packages

Basically I can create a class in the project and define if the string is null or not.

Now I can download a nuget package and if I look at a string property of some class it will tell me it is not nullable. But I know that it can be nullable.

So what do I do about that? Is the perfect world a long way ahead?

Here is an example Download nuget package RestSharp

Write this line

var response = new RestClient().ExecuteGetAsync(new RestRequest());

var myNullVariable = response.ErrorException;

Visual Studio doesn't tell you that it can be null.

References may have one of three states:

  1. Nullable
  2. Not nullable
  3. Oblivious

The first two are (relatively) obvious. The last state wouldn't exist if NRT was introduced with .NET 1.0, and exists only for backwards compatibility. When consuming code which is not annotated (whether in your own projects or via a NuGet package) its references are considered oblivious to nullability. These references flow through your code just as they did prior to the introduction of NRT.

All that to say: Any package you reference will have to annotate its code before you can take full advantage of NRT while working with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM