[英]Non-Nullable Property Must Contain A Non-Null Value
Is there any way to handle the "Non-Nullable Property Must Contain A Non-Null Value" alert in Visual Studio for mac.有没有办法在 Visual Studio for mac 中处理“非空属性必须包含非空值”警报。 Well, I can't find a way to disable it by removing the line from the csproj project file or configuration.
好吧,我找不到通过从 csproj 项目文件或配置中删除该行来禁用它的方法。 These warnings are in my database models and views and the idea is to proceed in the best way.
这些警告在我的数据库模型和视图中,我们的想法是以最好的方式进行。 It should be said that I am using.Net 6.0
应该说我用的是.Net 6.0
Thank you in advance for taking the time to read this question.提前感谢您抽出宝贵时间阅读此问题。
I'm assuming you have nullable reference types enabled.我假设您启用了可为空的引用类型。 There's a number of ways you can deal with this.
有很多方法可以解决这个问题。
public class SomeType { public string SomeProperty { get; set; } = default;; }
#nullable disable // at the top of the file #nullable restore // after the block of code you wanted to temporarily disable
<Nullable>
setting in your project file.<Nullable>
设置。 (It defaults to enabled in .NET 6) I would try to stick to #1 exclusively.我会尽量坚持#1。 Leave #3 alone if the intention is to make the transition.
如果打算进行过渡,请不要理会#3。
I came across the same situation, and found this article: Nullable reference types in C# it can enlighten the OP's doubt.我遇到了同样的情况,发现这篇文章: Nullable reference types in C#它可以启发OP的疑问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.