The following piece of code will always return true unless the variable v
is null
:
v is dynamic
and the following
There will always be a run-time type as others have said.
There is a hack to detect for local variables, relying on the fact that dynamic variables doesn't support extension methods.
static void DummyDynamicTest(this T t) //extension method
{
}
dynamic test = 1;
try
{
test.DummyDynamicTest();
//not dynamic
}
catch (RuntimeBinderException)
{
//dynamic
}
However you can't refactor the functionality into another method. This can't be very useful at all in any meaningful scenarios, ignore at any cost.