How do I check for type equality (is operator or x.GetType() == typeof(xType)) in IronPython?
-
20-08-2019 - |
Question
Duplicate: What’s the canonical way to check for type in python?
How do I check for type equality in IronPython?
I need the equivalent of the following C# code in IronPython:
if (x.GetType() == typeof(xType))
or
if (x is xType)
Solution
from System import *
if x.GetType() == Type.GetType(xType):
OTHER TIPS
Say C is a static class, not fully qualified but imported into the iron python script x is an instance of C And A.B.C is the fully qualified name
Why don't these work?
x.GetType() == Type.GetType("A.B.C")
OR
x is Type.GetType("A.B.C")
OR
x is C
OR
x.GetType() == Type.GetType(C)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow