Code below is compiled using C# 9 compiler in Visual Studio 2019.
According to Why does VS warn me that typeof(T) is never the provided type in a generic method where the type parameter is restricted to implement T? second answer typeof(TPocoTest)
is C# Type type which is never derived from PocoBaseTest
type.
C# compiler should thow warning but actually it compiles without warning.
How to force Visual Studio to throw error or warning on this ?
class PocoBaseTest { }
class PalkTest : PocoBaseTest { }
class EntityBaseTest<TPocoTest> where TPocoTest : PocoBaseTest
{
void Test()
{
// Warning
// CS0184 The given expression is never of the provided('PocoBaseTest') type
// does not occur.
if (typeof(TPocoTest) is PocoBaseTest)
return;
}
}
typeof(TPocoTest) is string
throws warning as epxected.