例如我有 xUnit 測驗
var record = _context.Records.Where(x => x.Foo == FooValue).FirstOrDefault();
// This check WILL NOT prevent the warning from being displayed
Assert.NotNull(record);
// This check WILL prevent the warning from being displayed
if (record == null) throw new Exception();
// Warning CS8602 "record may be null here"
Assert.True(record.Foo == FooValue);
包的所有者(通常)可以以某種方式指示編譯器該方法的輸出符合警告 CS8602?我使用了幾個包,我看到不相關的警告,我不想放置
#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning restore CS8602 // Dereference of a possibly null reference.
到處。如果可能的話,我至少會在我擁有的軟體包中解決這個問題。
uj5u.com熱心網友回復:
要解決可為空的警告,您可以使用!在c#中
檢查這個: https ://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings
例如: Assert.True(record.Foo! == FooValue);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/515113.html
