Exists
返回
true
当球场
_value
null
StreamReader
ReSharper
是在警告我这可能是
无效的
if(Exists)
早些时候不会。
我用注释禁用了警告,但我想知道是否有更干净的方法或一些注释或其他技巧
再竖琴
了解使用它是安全的
什么时候
Exists == true
?
internal class User
{
private readonly string _value;
internal User([NotNull] string name, [CanBeNull] string value)
{
_value = value;
}
public bool Exists => !(_value is null);
public async Task CopyToAsync(Stream stream)
{
if (Exists)
{
// ReSharper disable once AssignNullToNotNullAttribute - '_value' won't be null here
using (var valueStream = _value.ToStreamReader())
{
await valueStream.BaseStream.CopyToAsync(stream);
}
}
}
}