C
C#3y ago
OptoCloud

Safe to ignore non-null value on exit contructor? (disabling warning)

Can I safely add this as a ignore? I don't really know how I would fix this otherwise
5 Replies
Thinker
Thinker3y ago
You can write = null!; after the { get; set; } and that will force the compiler to shut up. And yes for EF you can safely ignore it as EF will set that property before you can access it, but the compiler can't know that.
OptoCloud
OptoCloudOP3y ago
im guessing adding a prabma is also fine?
Thinker
Thinker3y ago
yep You could also do #nullable disable at the top of the file
Angius
Angius3y ago
And when C# 11 arrives, required properties will be the solution to this issue
OptoCloud
OptoCloudOP3y ago
Im already using it :) Forces me to initialize that property when i construct the type
Want results from more Discord servers?
Add your server