ReSharper 建议将模式匹配代码更改为对象模式

ReSharper suggests changing pattern matching code to object pattern

ReSharper 建议更改以下代码:

if (MyString is string myString)
{
    //...
}

对象模式:

if (MyString is { } myString)
{
    //...
}

它说:

The source expression is always of pattern's type, matches on all non-null values.

我以前从未见过这种语法,也找不到它的任何文档。它是什么以及它有什么作用?

{} 代表 not null,但不调用 != 运算符,因此它是安全的,就像 is null 运算符不调用 == 运算符。

缺少相关信息。我在 github 上找到了关于它的帖子。我认为这是目前的预览功能。