c# - 函数返回后是否可以将参数的属性标记为空/非空?
问题描述
如果我有一个 function bool Foo(string? input)
,那么我可以对其进行注释以表明如果 return 是true
theninput
不为 null:
public static bool Foo([NotNullWhen(true)] string? input)
是否可以对参数的属性执行此操作(或类似的操作)?我在想一些事情
public class AClass { string? NullableString {get;set;}}
public static bool Foo([PropertyNotNullWhen(true, nameof(AClass.NullableString))] AClass input)
我认为MemberNotNullWhen
在这种情况下不会起作用,因为它仅适用于方法、属性和索引器,而不适用于它们的参数。
解决方案
推荐阅读
- excel - 在 VBA 上获取日期的活动过滤器
- java - 测试运行器选项卡在 Intellij 中消失了
- c++ - 在 C++ 中是否有计算 nCr 的内置函数?
- compilation - 使用上下文无关文法指定的编程语言如何能够表达图灵机?
- oracle - Oracle触发器在插入其他表后增加另一个表中的值
- python-imaging-library - 所有图像都带有 Exif 方向标签吗?
- javascript - javascript break in for-await 循环完成生成器
- unity3d - Touch.rawPosition - Touch.Position 而不是 Touch.position - (以前保存的)Touch.position?
- javascript - NextJS getServerSideProps 分页
- java - 我想打印数字值但它不起作用