I have a similar code:
if (variable !is AnyType)
{
// TODO
}
But what is that !is
? It compiles only in C# preview and Rider doesn't show any errors.
I have a similar code:
if (variable !is AnyType)
{
// TODO
}
But what is that !is
? It compiles only in C# preview and Rider doesn't show any errors.
In your comments you say this is Rider not telling you that it is invalid.
However, it is invalid code. You will not be able to compile C# code using this construct.
However, it also seems that Rider doesn't indicate that this is invalid code:
It should add "squigglies" beneath the code, like in this example:
So this seems to be a bug in the parser that handles syntax highlighting and validation.
Regardless of this, the code is invalid, and does not compile:
Judging from lv Misticos' (now deleted) answer, this may be legal code in C# 8 preview, but right now it is invalid.
OK, now it became clear.
In C# 8 preview, the ! is not associated with the is
operator, it is associated with the variable, so what you have is understood as this:
if (variable! is AnyType)
Let me rephrase that in pseudo-code:
if (variable /* that isn't null, honestly, just trust me*/ is AnyType)
So yes, this is in fact going to be legal C# code if all plans for C# 8 come to fruition.
I guess JetBrains have added support for syntax highlighting of C# 8 things ahead of time. I still say it is some form of bug in Rider though, they shouldn't allow future C# syntax until it is actually supported. For instance, I do not have C# 8 or any such preview installed so the latest C# Rider is able to use on my PC is 7.3 (I think).