有沒有辦法在 Visual Studio for mac 中處理“非空屬性必須包含非空值”警報。好吧,我找不到通過從 csproj 專案檔案或配置中洗掉該行來禁用它的方法。這些警告在我的資料庫模型和視圖中,我們的想法是以最好的方式進行。應該說我用的是.Net 6.0
提前感謝您抽出寶貴時間閱讀此問題。
uj5u.com熱心網友回復:
我假設您啟用了可為空的參考型別。有很多方法可以解決這個問題。
- 將這些屬性顯式初始化為默認值或已知值。
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>專案檔案中的設定。(在 .NET 6 中默認啟用)
我會盡量堅持#1。如果打算進行過渡,請不要理會#3。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/416519.html
標籤:
