更新到后抛出CA1062!参数空值检查

Mat*_*ard 10 c# visual-studio .net-6.0 c#-10.0 c#-11.0

根据 CA1062,外部可见方法中需要进行 null 检查,如下所示:

public static double GetLongitude(this Location location)
{
    if(location is null)
    {
        throw new ArgumentNullException(nameof(location));
    }

    return location.Longitude;
}
Run Code Online (Sandbox Code Playgroud)

我现在已经更新到.net 6.0并尝试使用参数null检查“!!”:

public static double GetLongitude(this Location location!!) => location.Longitude;
Run Code Online (Sandbox Code Playgroud)

但这又抛出了CA1062。

希望你们能帮助我:-)

Pan*_*vos 14

C# 10/.NET 6 中没有这样的运算符。参数 null 检查是针对即将推出的 C# 11 的一项提案,由于开发人员于 2022 年 4 月提出反对,该提案最终被推迟。