how to convert “var f = userState as Fault” from c# to ironpython
I want to convert C# statement
var f = userState as Fa开发者_运维技巧ult
to ironpython statement
There are two parts to this.
If you are just trying to cast userState to a Fault then you don't need to do anything as Python is weakly typed.
If you are trying to determine if userState is of type Fault then try this
from System import *
if userState.GetType() == Type.GetType(Fault):
...
Without seeing the next line, it's hard to know what your intent is.
If you're downcasting (say from object
to Fault
) - you don't have to! In IronPython members are looked up at runtime, so if userState
is already a Fault
you can treat it as one without any casting.
If you're trying to trigger an explicit/implicit conversion, use clr.Convert
.
If you're checking if userState
is a Fault
, use isinstance(userState, Fault)
.
精彩评论